Adding Functions - Game not updating?
by Aaron Varshney · in Torque Game Builder · 03/06/2005 (8:55 am) · 6 replies
This is going to sound a little weird (or whether it's common I'm not sure), but at first when I was adding the code (I'm using the tutorial) into the SetupT2DScene function everything was working, changing values and the game would update. Then it got to the point where I had to add controls to the game, added that then I had to create the functions, now this is where everything started to go a little strange.
I added the Up movement, all went well, great! I then added the Down movement....ok that's weird, it didn't work, so I thought "the game didn't update for some reason", so I tested that theory by changing the size and position of the ship, nope, nothing changed, so I left the changes, deleted the Down movement and it worked!
Well after all that I thought "lets add all of the control functions", well it behaved in the same manner, I commented out the Down AND Left movement and again changed the position and size of the ship, both moving Left and Up worked, but if I uncomment Down and Right and again change the position and size of the ship it doesn't work and plays as it was beforehand...
Is this a bug or is there something strange going on? The same happens when I put the code into seperate functions.
I added the Up movement, all went well, great! I then added the Down movement....ok that's weird, it didn't work, so I thought "the game didn't update for some reason", so I tested that theory by changing the size and position of the ship, nope, nothing changed, so I left the changes, deleted the Down movement and it worked!
Well after all that I thought "lets add all of the control functions", well it behaved in the same manner, I commented out the Down AND Left movement and again changed the position and size of the ship, both moving Left and Up worked, but if I uncomment Down and Right and again change the position and size of the ship it doesn't work and plays as it was beforehand...
Is this a bug or is there something strange going on? The same happens when I put the code into seperate functions.
function setupT2DScene()
{...
// Add your custom code here...
datablock fxImageMapDatablock2D(playershipImageMap) {
mode = full;
textureName = "~/client/images/PlayerTirou";
};
$player1 = new fxStaticSprite2D() {
scenegraph = t2dSceneGraph;
};
$player1.setPosition("0 30");
$player1.setSize("10");
$player1.setRotation(180);
$player1.setImageMap(playershipImageMap);
new ActionMap(plyr1Ctrl);
plyr1Ctrl.bindCMD(keyboard, "q", "FlyFWD();", "FlyFWDstop();");
plyr1Ctrl.bindCMD(keyboard, "a", "FlyDWN();", "FlyDWNStop();");
plyr1Ctrl.bindCMD(keyboard, "o", "FlyLFT();", "FlyLFTStop();");
plyr1Ctrl.bindCMD(keyboard, "p", "FlyRGT();", "FlyRGTStop();");
plyr1Ctrl.bindCMD(keyboard, "space", "Laser();", "");
plyr1Ctrl.bindCMD(keyboard, "s", "Bomb();", "");
plyr1Ctrl.bindCMD(keyboard, "w", "UseSpecial();", "");
plyr1Ctrl.bindCMD(keyboard, "1", "Plyr1Special1();", "");
plyr1Ctrl.bindCMD(keyboard, "2", "Plyr1Special2();", "");
plyr1Ctrl.bindCMD(keyboard, "3", "Plyr1Special3();", "");
plyr1Ctrl.push();
}
function FlyFWD() { $player1.setLinearVelocityY(-10); }
function FlyBCK() { $player1.setLinearVelocityY(+10); }
function FlyLFT() { $player1.setLinearVelocityX(-10); }
function FlyRGT() { $player1.setLinearVelocityX(+10); }
function FlyFWDStop() { $player1.setLinearVelocityY(0); }
function FlyBCKStop() { $player1.setLinearVelocityY(0); }
function FlyLFTStop() { $player1.setLinearVelocityX(0); }
function FlyRGTStop() { $player1.setLinearVelocityX(0); }
function Laser() {}
function Bomb() {}
function UseSpecial() {}
function Plyr1Special1() {}
function Plyr1Special2() {}
function Plyr1Special3() {}About the author
#2
An additional note here... Check the console while you're attempting to move down and the console should report that you're trying to call an invalid function every time you press "a"
03/06/2005 (9:07 am)
Well, in your binds, it looks like you have FWD, DWN, LFT, RGT, but in your functions, you have FWD, BCK, LFT, RGT. So either your bind or your function needs to be the same for BCK or DWN, whichever it is supposed to be. An additional note here... Check the console while you're attempting to move down and the console should report that you're trying to call an invalid function every time you press "a"
#3
If your game doesn't work quite right, look in the console for errors, or scan the console.log file for problems.
To force a recompile of your .cs file, just rename the appropriate .dso file and see what happens. If it goes completely bananas, put the old one back, and start scanning your code for problems.
03/06/2005 (9:11 am)
Also, if there is an error in your code, T2D will use the last successfully compiled version of it (the .dso) file.If your game doesn't work quite right, look in the console for errors, or scan the console.log file for problems.
To force a recompile of your .cs file, just rename the appropriate .dso file and see what happens. If it goes completely bananas, put the old one back, and start scanning your code for problems.
#4
03/06/2005 (11:48 am)
Quote:I had this same problem.I'm using EditPlus, I'll try reinstalling it to see if it makes any difference.
What script editor are you using.
What I did was re-download my editor and everything seemed to work just fine.
Quote:Well, in your binds, it looks like you have FWD, DWN, LFT, RGT, but in your functions, you have FWD, BCK, LFT, RGT.This bit I feel like an idiot, I changed it so it is the same now but still unfortunately I get the same problem, only Forwards and Left works...
Quote:scan the console.log file for problems.That's a big help, I should've looked at this from the start cheers, but still it's a rather strange one:
--------- Initializing MOD: T2D ---------
Compiling BattleBeyondtheEarth/client/client.cs...
BattleBeyondtheEarth/client/client.cs Line: 123 - Syntax error.
>>> Advanced script error report. Line 245.
>>> Some error context, with ## on sides of error halt:
^$player1.setLinearVelocityY(-10);
}
function FlyBCK() {
^$player1.setLinearVelocityY(+1##0##);
}
function FlyLFT() {
^$player1.setLinearVelocityX(-10);
>>> Error report complete.T2D Engine initialized... <input> (0): Unable to find function FlyFWDstop <input> (0): Unable to find function FlyBCK <input> (0): Unable to find function FlyBCKStop <input> (0): Unable to find function FlyLFT <input> (0): Unable to find function FlyLFTStop <input> (0): Unable to find function FlyRGT <input> (0): Unable to find function FlyRGTStopAnd I've changed the errors as shown, though it's strange how in the logs it thinks there's a double hash in the backwards movement...
#5
03/06/2005 (11:54 am)
The ## is telling you that there is a problem with this part of your script. In this instance, the problem is that you used a + to specify a positive number, which is unnecessary. Try taking out the + and see what happens.
#6
I can't believe it was because of a positive value, I saw the tutorial showing a + so that's what I was using, I guess there's a slight mistake in the tutorial there then. ;-)
Cheers guys.
03/06/2005 (1:51 pm)
You rock!I can't believe it was because of a positive value, I saw the tutorial showing a + so that's what I was using, I guess there's a slight mistake in the tutorial there then. ;-)
Cheers guys.
Torque Owner Bob
What script editor are you using.
What I did was re-download my editor and everything seemed to work just fine.
Bob