Game Development Community

Functions problem

by Daniel Brown · in Torque Game Engine · 04/09/2004 (5:02 am) · 7 replies

Hey all,

for some reason everytime i create a function then bind it to a key in the default.bind.cs, when i press the key in the game, nothing happens. And when i look at the console it just says 'blahblah function unknown'. this is what i have added:

function modeSwitch(%val)
{
if($spccnd == 1)
{
cursorOff();
moveMap.bind( mouse, xaxis, yaw );
moveMap.bind( mouse, yaxis, pitch );
moveMap.bind( mouse, button0, mouseFire );
toggleFirstPerson

$spccnd = 0
}
else if($spccnd == 0)
{
cursorOn();
toggleFirstPerson
$spccnd = 1
}
}

moveMap.bind(keyboard, "space", modeSwitch);

What is meant to happen is there is 2 modes you can go into, attack and normal. But when you are in attack mode the player can use the mouse to aim, and look etc. But in normal he can use the mouse normally to select things. but i dont want any help with the code itself just why my functions can never be found in the game, do i have to add my function to the server side scripts as well??

Thanks

#1
04/09/2004 (11:28 am)
The code listed will not compile that is why it is not usable. Since you dont want any help, that is about all I can tell you.
#2
04/09/2004 (11:41 am)
Daniel, when you load Torque open the console with "'" and scroll up, you should see a load of red stuff pointing you to the compile errors. There's plenty wrong with your code too, missing ()s and ;s to start with.


Ian
#3
04/09/2004 (6:00 pm)
Well i changed my mind :) could u point out whast wrong for me please?

Thanks
#4
04/09/2004 (6:17 pm)
As Ian said, use your console. It will show you exactly where your syntax errors are. Hit the tilde key in game and it will open the console. Scroll to where it shows the syntax errors and you can see the problems.
#5
04/09/2004 (7:11 pm)
As was stated above the console is very helpful on identifying syntax errors.

Torque Script Documentation may help you as well.

function modeSwitch(%val)
{
   if($spccnd == 1)
   {
      cursorOff();
      moveMap.bind( mouse, xaxis, yaw );
      moveMap.bind( mouse, yaxis, pitch );
      moveMap.bind( mouse, button0, mouseFire );
      //[b]toggleFirstPerson[/b]
This is the first line that is obviously incorrect, Nearly every statement needs to be terminated with a semicolon to allow the program to advance. There are a couple exceptions: If statements and function definitions for example. Also If this is a function call, you need to add the () to the end of it. Like so:
toggleFirstPerson();

      [b]$spccnd = 0[/b] also missing a semicolon. 

      $spccnd = 0;
   }
   else if($spccnd == 0)
   {
      cursorOn();
      //[b]toggleFirstPerson[/b] again as above should be.
      toggleFirstPerson();
      //[b]$spccnd = 1[/b] missing semicolon.
      $spccnd = 1;
   }
}
This should get you started, and be sure to read everything you can about the scripting language. There is so much to learn.
#6
04/09/2004 (7:42 pm)
Daniel Brown,

Please don't cross post. I have already give you a good example on how to solve your problem at Keyboard input. No point helping anyone who don't read documentation.

-james yong
#7
04/10/2004 (2:06 am)
Sorry, i have tried your code, but i wanted to try and make my own as well so that i learn from my mistakes. It's all working now, thanks all!