Binding keys
by _____ · in Torque Game Engine · 09/18/2005 (11:51 am) · 16 replies
Hi
guys i cant seem to get binding keys to work,are there any tutorials explaing how the right way to to this is?
guys i cant seem to get binding keys to work,are there any tutorials explaing how the right way to to this is?
About the author
#2
Advanced 3D Game Programming All In One (the book) has examples of key binding.
09/18/2005 (1:05 pm)
Note that config.cs should be deleted anytime you change the default bindings in the client's default.bind.cs. If the config.cs doesn't exist, it will re-build it based on the defaults in default.bind.cs. If config.cs does exist, then it over-rules your default settings, thus allowing customization of the key bindings by the end user...Advanced 3D Game Programming All In One (the book) has examples of key binding.
#3
09/18/2005 (10:37 pm)
Thanks for the help guys
#4
I had trouble, so now I see what you wrote about the default.bind.cs file, so I'm thinking: maybe I should name one of my files that? But do I need to put it in a "client" folder? I figured that I didn't need a 'client' folder. I just have this one script folder. Is that a problem? I have this file in my script folder called: "Controls.cs". I put this code:
function movePaddleRight()
{
paddle.Move(1, 20);
echo("moved right");
}
function movePaddleLeft()
{
paddle.Move(0, 20);
echo("moved left");
}
$speed = 50;
moveMap.bind( keyboard, "d", movePaddleRight );
moveMap.bind( keyboard, "a", movePaddleLeft);
(I'd rather just use left/right, but I switched to d/a keys, in case that was what was causing me the problem)
This doesn't work at all, so I guess these things aren't binded. I've found that sometimes Config.cs in the starter.fps folder gets changed when I start the mod. It'll add 2 lines like this:
moveMap.bind( keyboard, "d", );
moveMap.bind( keyboard, "a", );
It will only add those lines to config.cs if I don't put the "d" and the "a" in the bind calls in quotes. The 2 added lines will of course, cause a syntax error. I find it odd that starter.fps\client\config.cs gets changed at all, because Arkanoid has nothing to do with starter.fps, its supposed to be its own game, right?
Anyway, I put them in quotes, and that got rid of the syntax errors/changes to config.cs, but it still doesn't work at all.
09/19/2005 (11:21 am)
I'm having trouble binding keys, myself. I tried making my own mod, its called: "Arkanoid", in its own folder (just like starter.fps and starter.racing doesn't have their own folders).I had trouble, so now I see what you wrote about the default.bind.cs file, so I'm thinking: maybe I should name one of my files that? But do I need to put it in a "client" folder? I figured that I didn't need a 'client' folder. I just have this one script folder. Is that a problem? I have this file in my script folder called: "Controls.cs". I put this code:
function movePaddleRight()
{
paddle.Move(1, 20);
echo("moved right");
}
function movePaddleLeft()
{
paddle.Move(0, 20);
echo("moved left");
}
$speed = 50;
moveMap.bind( keyboard, "d", movePaddleRight );
moveMap.bind( keyboard, "a", movePaddleLeft);
(I'd rather just use left/right, but I switched to d/a keys, in case that was what was causing me the problem)
This doesn't work at all, so I guess these things aren't binded. I've found that sometimes Config.cs in the starter.fps folder gets changed when I start the mod. It'll add 2 lines like this:
moveMap.bind( keyboard, "d", );
moveMap.bind( keyboard, "a", );
It will only add those lines to config.cs if I don't put the "d" and the "a" in the bind calls in quotes. The 2 added lines will of course, cause a syntax error. I find it odd that starter.fps\client\config.cs gets changed at all, because Arkanoid has nothing to do with starter.fps, its supposed to be its own game, right?
Anyway, I put them in quotes, and that got rid of the syntax errors/changes to config.cs, but it still doesn't work at all.
#5
STARTER.FPS
You see config.cs changing because it is a script that saves the user's preferred bindings... If you delete config.cs and config.dso (the compiled version of config.cs), config.cs will be re-created with the settings in the client's default.bind.cs script and re-compiled to config.dso during the first execution.
The user's perferred bindings from config.cs are loaded/run by the exec("./config.cs") found in /client/init.cs...
In main.cs and optionsDlg.cs you'll find where moveMap.save("./client/config.cs") saves the user's preferred bindings to config.cs. If no config.cs exists, it makes a new one... If the user changes their preferences, config.cs is modified to reflect those changes...
*Note that the way I found that out was by searching for "config.cs" in all of the script files... The TorqueDev Development IDE editor (www.torquedev.com/) has a nifty "Search files in project" option that aided in that process.
Your mod
I bet you will find the moveMap.save() function somewhere in the scripts of your mod... that's why config.cs is changing. Try deleting config.cs and config.dso, and you'll see that it comes back when you re-run your mod... So config.cs is probably not the best place to put your bindings if you want them to stick. I recommend trying to put them into another file after deleting config.cs and config.dso, then re-run your mod and see how it works out.
Techinically, you don't have to follow the file naming conventions or directory structure of the starter.fps or racer.fps examples. I'd recommend it, because they are set up well... but you can do it however you want. I'd also recommend that you search all of your *.cs files for the word "bind" to see where all the binding takes place and learn from how it's done there.
Some further debugging techniques could include going to the console while running your mod (press ~), and trying to run the functions you defined, like movePaddleRight(); See if it echoes back to you "moved right". If not, there may have been a bug in your script and it didn't compile to opcode, so you're actually running an older version of the file (the last time it was run buggless and compiled correctly to opcode, but not the version from the latest source code). You can search the console.log file for clues about why it didn't compile correctly. Another way to see if it compiled correctly is to look at the datestamp (time of file creation) for Controls.dso -- is it before the datestamp for Controls.cs? If so, it didn't compile right... Find your syntax error or bug, save the new Controls.cs, and re-run the mod.
If it still doesn't work after all that, look at where the other "bind" references are when you search all the *.cs files. Are there other bindings for the same keys in other files that are over-writing yours?
If that doesn't work, pray... :) Or come back to the forums for more ideas... or figure out how to step through the scripted code with the debugger...
More on Binding
You may want to change the bound functions to have an argument. For example:
www.garagegames.com/mg/forums/result.thread.php?qt=16345 shows thie example to help with understanding how to use %val with key binding and bound functions:
Official documentation on ActionMaps: www.garagegames.com/docs/tge/general/ch06s07.php
09/19/2005 (5:28 pm)
@Eric: More about binding keys...STARTER.FPS
You see config.cs changing because it is a script that saves the user's preferred bindings... If you delete config.cs and config.dso (the compiled version of config.cs), config.cs will be re-created with the settings in the client's default.bind.cs script and re-compiled to config.dso during the first execution.
The user's perferred bindings from config.cs are loaded/run by the exec("./config.cs") found in /client/init.cs...
In main.cs and optionsDlg.cs you'll find where moveMap.save("./client/config.cs") saves the user's preferred bindings to config.cs. If no config.cs exists, it makes a new one... If the user changes their preferences, config.cs is modified to reflect those changes...
*Note that the way I found that out was by searching for "config.cs" in all of the script files... The TorqueDev Development IDE editor (www.torquedev.com/) has a nifty "Search files in project" option that aided in that process.
Your mod
I bet you will find the moveMap.save() function somewhere in the scripts of your mod... that's why config.cs is changing. Try deleting config.cs and config.dso, and you'll see that it comes back when you re-run your mod... So config.cs is probably not the best place to put your bindings if you want them to stick. I recommend trying to put them into another file after deleting config.cs and config.dso, then re-run your mod and see how it works out.
Techinically, you don't have to follow the file naming conventions or directory structure of the starter.fps or racer.fps examples. I'd recommend it, because they are set up well... but you can do it however you want. I'd also recommend that you search all of your *.cs files for the word "bind" to see where all the binding takes place and learn from how it's done there.
Some further debugging techniques could include going to the console while running your mod (press ~), and trying to run the functions you defined, like movePaddleRight(); See if it echoes back to you "moved right". If not, there may have been a bug in your script and it didn't compile to opcode, so you're actually running an older version of the file (the last time it was run buggless and compiled correctly to opcode, but not the version from the latest source code). You can search the console.log file for clues about why it didn't compile correctly. Another way to see if it compiled correctly is to look at the datestamp (time of file creation) for Controls.dso -- is it before the datestamp for Controls.cs? If so, it didn't compile right... Find your syntax error or bug, save the new Controls.cs, and re-run the mod.
If it still doesn't work after all that, look at where the other "bind" references are when you search all the *.cs files. Are there other bindings for the same keys in other files that are over-writing yours?
If that doesn't work, pray... :) Or come back to the forums for more ideas... or figure out how to step through the scripted code with the debugger...
More on Binding
You may want to change the bound functions to have an argument. For example:
function movePaddleRight(%val)You'll notice in starter.fps's default.bindings.cs that the bound functions have that variable. %val will be non=zero when the key is pressed down, and it will be 0 when the bound key is released.
www.garagegames.com/mg/forums/result.thread.php?qt=16345 shows thie example to help with understanding how to use %val with key binding and bound functions:
// In script, youll want something like the following to add the binding:
GlobalActionMap.bind(keyboard, "w", myFunction);
// Then define the function like so:
function myFunction(%val)
{
if(%val) {
// Key down
} else {
// Key up
}
}Official documentation on ActionMaps: www.garagegames.com/docs/tge/general/ch06s07.php
#6
I'm not sure what you mean there. Do you mean that it will be 1 when the key is down, and 0 when the key is released?
I tried using "echo" calls inside of my binded functions, but these echos are never called, so they must not have been bound properly.
The paddle itself is a GuiBitmapCtrl, don't know if that helps.
If I do get this to work, and have the arrows moving the paddle, it will probably work no matter what context the player is in (the menu or the game). I'd like to be able to restrict it to the gamestate the player is in. Of course, I could just keep a global variable called: $gamestate, that wouldn't be hard.
[quote]I bet you will find the moveMap.save() function somewhere in the scripts of your mod... [quote]
no, that's not anywhere in my script.
The TorqueDev Development IDE editor (www.torquedev.com/) has a nifty "Search files in project"
yup, that thing's usefull. Just found out about it 2 days ago.
Some further debugging techniques could include going to the console while running your mod (press ~), and trying to run the functions you defined, like movePaddleRight()
that's a good idea. Yup, the function itself works, its just not binded.
If it still doesn't work after all that, look at where the other "bind" references are when you search all the *.cs files. Are there other bindings for the same keys in other files that are over-writing yours?
Ok, I'll look at that, and get back to you. I'll check that Controls.dso thing as well.
In default.bind.cs, I find these bindings: probably from the starter.fps client.
moveMap.bind( keyboard, a, moveleft );
moveMap.bind( keyboard, d, moveright );
These could be overriding non-functional functions. So now, I've tried organizing my folders like the starter.fps example. There's a client folder, which holds my init.cs and my new config.cs that looks like this:
09/21/2005 (5:54 am)
Jason Howard said:%val will be non=zero when the key is pressed down, and it will be 0 when the bound key is released.I'm not sure what you mean there. Do you mean that it will be 1 when the key is down, and 0 when the key is released?
I tried using "echo" calls inside of my binded functions, but these echos are never called, so they must not have been bound properly.
The paddle itself is a GuiBitmapCtrl, don't know if that helps.
If I do get this to work, and have the arrows moving the paddle, it will probably work no matter what context the player is in (the menu or the game). I'd like to be able to restrict it to the gamestate the player is in. Of course, I could just keep a global variable called: $gamestate, that wouldn't be hard.
[quote]I bet you will find the moveMap.save() function somewhere in the scripts of your mod... [quote]
no, that's not anywhere in my script.
The TorqueDev Development IDE editor (www.torquedev.com/) has a nifty "Search files in project"
yup, that thing's usefull. Just found out about it 2 days ago.
Some further debugging techniques could include going to the console while running your mod (press ~), and trying to run the functions you defined, like movePaddleRight()
that's a good idea. Yup, the function itself works, its just not binded.
If it still doesn't work after all that, look at where the other "bind" references are when you search all the *.cs files. Are there other bindings for the same keys in other files that are over-writing yours?
Ok, I'll look at that, and get back to you. I'll check that Controls.dso thing as well.
In default.bind.cs, I find these bindings: probably from the starter.fps client.
moveMap.bind( keyboard, a, moveleft );
moveMap.bind( keyboard, d, moveright );
These could be overriding non-functional functions. So now, I've tried organizing my folders like the starter.fps example. There's a client folder, which holds my init.cs and my new config.cs that looks like this:
moveMap.delete(); new ActionMap(moveMap); moveMap.bind(keyboard, "right", movePaddleRight); moveMap.bind(keyboard, "left", movePaddleLeft);
#7
Perhaps you never pushed moveMap in your code? Does adding the following after binding help?
09/21/2005 (4:16 pm)
Here's some ActionMap related examples: %actionMap.push(%map) - Pushes a new keybind map onto the stack %actionMap.pop(%map) - Pulls a keybind map off the stack %actionMap.bind() - Binds a key to a function, sends True/False on keydown/keyup %actionMap.bindCmd() - Binds a key to 1 or 2 functions for keydown and keyup independantly %actionMap.unbind() - Removes a Bind %actionMap.save(%file,%append) %actionMap.getBinding(%command) %actionMap.getCommand(%device,%control)
Perhaps you never pushed moveMap in your code? Does adding the following after binding help?
moveMap.push();
#8
Perhaps you never pushed moveMap in your code? Does adding the following after binding help?
09/21/2005 (5:05 pm)
Here's some ActionMap related examples: %actionMap.push(%map) - Pushes a new keybind map onto the stack %actionMap.pop(%map) - Pulls a keybind map off the stack %actionMap.bind() - Binds a key to a function, sends True/False on keydown/keyup %actionMap.bindCmd() - Binds a key to 1 or 2 functions for keydown and keyup independantly %actionMap.unbind() - Removes a Bind %actionMap.save(%file,%append) %actionMap.getBinding(%command) %actionMap.getCommand(%device,%control)
Perhaps you never pushed moveMap in your code? Does adding the following after binding help?
moveMap.push();
#9
1) delete ./client/config.cs
2) delete ./client/config.dso
3) Edited ./client/scripts/default.bind.cs by adding the following at the end of the file:
5) Pressed tilde (~) key to see the following entries among the latest console entries:
You will notice that testBinding(%val) was called twice, but I only pressed the "a" key once. testBinding(1) was called when I pressed the "a" key down, and testBinding(0) was called when I released the "a" key. That being the case, I recommend the following for your code:
After running this, if it didn't work, go to config.cs and see what was saved there for the bindings to d and a. If that is messed up, consider changing the binding lines above and/or deleting the config.cs and config.dso files and trying again. That's how I debugged the example above when deciding how to reference the bound functions.
Does that help any?
09/21/2005 (5:05 pm)
Just as a reference point, I tried the following with TGE 1.3's starter.fps, and it worked:1) delete ./client/config.cs
2) delete ./client/config.dso
3) Edited ./client/scripts/default.bind.cs by adding the following at the end of the file:
function testBinding(%val)
{
if(%val) { // Key down
echo("Pressed bound key..." SPC %val);
} else { // Key up
echo("Released bound key..." SPC %val);
}
}
moveMap.bind(keyboard, "a", "testBinding");4) Re-ran the game... During gameplay I pressed and released the "a" key.5) Pressed tilde (~) key to see the following entries among the latest console entries:
Pressed bound key... 1 Released bound key... 0
You will notice that testBinding(%val) was called twice, but I only pressed the "a" key once. testBinding(1) was called when I pressed the "a" key down, and testBinding(0) was called when I released the "a" key. That being the case, I recommend the following for your code:
function movePaddleRight(%val)
{
if(%val) {
paddle.Move(1,20);
echo("moved right");
}
}
function movePaddleLeft(%val)
{
if(%val) {
paddle.Move(0,20);
echo("moved left");
}
}
$speed = 50;
moveMap.bind(keyboard, "d", "movePaddleRight");
moveMap.bind(keyboard, "a", "movePaddleLeft");After running this, if it didn't work, go to config.cs and see what was saved there for the bindings to d and a. If that is messed up, consider changing the binding lines above and/or deleting the config.cs and config.dso files and trying again. That's how I debugged the example above when deciding how to reference the bound functions.
Does that help any?
#10
I got the paddle moving left/right now. In a choppy fashion (you have to release the key many times) but its a start. Now, what I figure I should do is set 2 "boolean" variables called: movingLeft and movingRight, then reset the variable to false when the arrow key is released. If I were doing this in my own C++ game engine, I'd do it in a loop, in some function that gets called every frame, and multiply the amount its supposed to move by the time elapsed, but here, in Torque, I'm not sure what you're supposed to do.
One other thing still eludes me: Why is it that when I compile my key bindings, they end up in the config.cs of the starter.fps folder? It doesn't even end up anywhere in the Arkanoid folder. And why is it that the bindings that I made only seem to work when I'm in my game Gui, but not the main menu. Don't get me wrong: That's what I want, but I thought that I would have to specify this.
Edit: Ok, now I realise why. I call moveMap.push(); in the button to start the game. If I don't call it, I simply can't use this moveMap. Is it possible to have many different action maps? they don't all have to be called Movemap do they? Its odd though, I don't have any code that creates a movemap. I did, but I commented it out. I don't even know what this code is for:
Maybe I'm actually using the "movemap" from the starter.fps example?
09/22/2005 (5:45 am)
Yes, this helps alot actually. Thank you very much! I got the paddle moving left/right now. In a choppy fashion (you have to release the key many times) but its a start. Now, what I figure I should do is set 2 "boolean" variables called: movingLeft and movingRight, then reset the variable to false when the arrow key is released. If I were doing this in my own C++ game engine, I'd do it in a loop, in some function that gets called every frame, and multiply the amount its supposed to move by the time elapsed, but here, in Torque, I'm not sure what you're supposed to do.
One other thing still eludes me: Why is it that when I compile my key bindings, they end up in the config.cs of the starter.fps folder? It doesn't even end up anywhere in the Arkanoid folder. And why is it that the bindings that I made only seem to work when I'm in my game Gui, but not the main menu. Don't get me wrong: That's what I want, but I thought that I would have to specify this.
Edit: Ok, now I realise why. I call moveMap.push(); in the button to start the game. If I don't call it, I simply can't use this moveMap. Is it possible to have many different action maps? they don't all have to be called Movemap do they? Its odd though, I don't have any code that creates a movemap. I did, but I commented it out. I don't even know what this code is for:
//if ( isObject( moveMap ) ) // moveMap.delete(); //new ActionMap(moveMap);
Maybe I'm actually using the "movemap" from the starter.fps example?
#11
The code you commented out just makes sure that if moveMap already exists it is properly deleted before you re-create it... if it doesn't already exist, it just creates a new one.
Regarding the choppy behavior that requires mupltiple key presses... have you considered scheduling a resonse? The basic idea is to schedule a movement to take place every so many milliseconds; when the key is released, stop the scheduling. I think that's the Torque-ish way to go about this kind of thing.
Here's an example:
I pasted the above code onto the end of /client/scripts/default.bind.cs. If the 'a' key is pressed and held down for a couple seconds during gameplay, the following is sent to the console (~):
So basically, every 500 milliseconds, test_a_KeyScheduling() will be called while the bound key 'a' is held down. Using this method for your bound movement keys should give you smooth movement while holding down the keys. Adjust the 500 milliseconds to whatever you need... or even replace it with a $movementDelay variable so that you can adjust your speed during the game by changing the schedule delay time.
09/22/2005 (4:47 pm)
Yes, you can have several ActionMaps and name them whatever you want. You push & pop them to and from a stack to decide which is the currently activated one. For example, in an FPS if a character picks up some weapon that would require different key controls, you could add that action map to the stack and then remove it from the stack when you drop that weapon...The code you commented out just makes sure that if moveMap already exists it is properly deleted before you re-create it... if it doesn't already exist, it just creates a new one.
Regarding the choppy behavior that requires mupltiple key presses... have you considered scheduling a resonse? The basic idea is to schedule a movement to take place every so many milliseconds; when the key is released, stop the scheduling. I think that's the Torque-ish way to go about this kind of thing.
Here's an example:
function test_a_KeyScheduling()
{
// perform regular 'a' key reactions
echo("scheduled a key reaction...");
// schedule key press next reaction, assuming the key will continue to be pressed
$a_Key_ScheduledEventID = Schedule(500, 0, "test_a_KeyScheduling");
}
function testBinding(%val)
{
if(%val) { // Key down
echo("Pressed bound key..." SPC %val);
// schedule first regular resonse to key press
$a_Key_ScheduledEventID = Schedule(0, 0, "test_a_KeyScheduling");
} else { // Key up
echo("Released bound key..." SPC %val);
// cancel scheduled actions due to key release
Cancel($a_Key_ScheduledEventID);
}
}
moveMap.bind(keyboard, "a", "testBinding");I pasted the above code onto the end of /client/scripts/default.bind.cs. If the 'a' key is pressed and held down for a couple seconds during gameplay, the following is sent to the console (~):
Pressed bound key... 1 scheduled a key reaction... scheduled a key reaction... scheduled a key reaction... scheduled a key reaction... Released bound key... 0
So basically, every 500 milliseconds, test_a_KeyScheduling() will be called while the bound key 'a' is held down. Using this method for your bound movement keys should give you smooth movement while holding down the keys. Adjust the 500 milliseconds to whatever you need... or even replace it with a $movementDelay variable so that you can adjust your speed during the game by changing the schedule delay time.
#12
09/23/2005 (7:05 am)
Schedule! That's good stuff, I used that yesterday; very similar method to yours. But I didn't know how to cancel the schedule before, so thanks! I use a variable called: $interval for the schedule, and then just treat it like I would a main loop in any game.
#13
I did this stuff:
1) delete ./client/config.cs
2) delete ./client/config.dso
3) Edited ./client/scripts/default.bind.cs by adding the following at the end of the file:
function changeAmmo(){
FirstAmmoHUD.getBitmap = %curBit
if %curBit = "redAmmo.png"{
FirstAmmoHUD.SetBitmap(".\client\ui\blueAmmo.png");
FirstAmmoHUD.SetUpdate();
NextAmmoHUD.SetBitmap(".\client\ui\yellowAmmo.png");
NextAmmoHUD.SetUpdate();
LastAmmoHUD.SetBitmap(".\client\ui\redAmmo.png");
LastAmmoHUD.SetUpdate();
} else
if %curBit = "blueAmmo.png"{
FirstAmmoHUD.SetBitmap(".\client\ui\yellowAmmo.png");
FirstAmmoHUD.SetUpdate();
NextAmmoHUD.SetBitmap(".\client\ui\redAmmo.png");
NextAmmoHUD.SetUpdate();
LastAmmoHUD.SetBitmap(".\client\ui\blueAmmo.png");
LastAmmoHUD.SetUpdate();
} else
if %curBit = "yellowAmmo.png"{
FirstAmmoHUD.SetBitmap(".\client\ui\redAmmo.png");
FirstAmmoHUD.SetUpdate();
NextAmmoHUD.SetBitmap(".\client\ui\blueAmmo.png");
NextAmmoHUD.SetUpdate();
LastAmmoHUD.SetBitmap(".\client\ui\yellowAmmo.png");
LastAmmoHUD.SetUpdate();
}
}
moveMap.bind( keyboard, q, changeAmmo );
Something in my code is causing default.bind.cs not to compile so no .dso gets created and no keys get mapped. Can somebody drop me a hint on what I'm doing wrong?
BTW, FirstAmmoHUD etc are all GuiBitmapCtrl instances.
Thanks,
n8
06/01/2006 (12:21 am)
Hey, if you guys are still listening to this thread I have a question:I did this stuff:
1) delete ./client/config.cs
2) delete ./client/config.dso
3) Edited ./client/scripts/default.bind.cs by adding the following at the end of the file:
function changeAmmo(){
FirstAmmoHUD.getBitmap = %curBit
if %curBit = "redAmmo.png"{
FirstAmmoHUD.SetBitmap(".\client\ui\blueAmmo.png");
FirstAmmoHUD.SetUpdate();
NextAmmoHUD.SetBitmap(".\client\ui\yellowAmmo.png");
NextAmmoHUD.SetUpdate();
LastAmmoHUD.SetBitmap(".\client\ui\redAmmo.png");
LastAmmoHUD.SetUpdate();
} else
if %curBit = "blueAmmo.png"{
FirstAmmoHUD.SetBitmap(".\client\ui\yellowAmmo.png");
FirstAmmoHUD.SetUpdate();
NextAmmoHUD.SetBitmap(".\client\ui\redAmmo.png");
NextAmmoHUD.SetUpdate();
LastAmmoHUD.SetBitmap(".\client\ui\blueAmmo.png");
LastAmmoHUD.SetUpdate();
} else
if %curBit = "yellowAmmo.png"{
FirstAmmoHUD.SetBitmap(".\client\ui\redAmmo.png");
FirstAmmoHUD.SetUpdate();
NextAmmoHUD.SetBitmap(".\client\ui\blueAmmo.png");
NextAmmoHUD.SetUpdate();
LastAmmoHUD.SetBitmap(".\client\ui\yellowAmmo.png");
LastAmmoHUD.SetUpdate();
}
}
moveMap.bind( keyboard, q, changeAmmo );
Something in my code is causing default.bind.cs not to compile so no .dso gets created and no keys get mapped. Can somebody drop me a hint on what I'm doing wrong?
BTW, FirstAmmoHUD etc are all GuiBitmapCtrl instances.
Thanks,
n8
#14
FirstAmmoHud.getBitmap = %curBit
Second, the logic of that statement appears completely off--you appear to be wanting to use a get accessor method to assign a value, but instead are assigning a value to a dynamic field called getBitMap--and that value is always going to be empty since %curBit has never been defined prior to it's use in this scope.
A guess at what you really want here is something like:
%curBit = FirstAmmoHUD.getBitmap();
--that assumes that getBitmap() is an available method on the FirstAmmoHUD's namespace, and in fact returns a string that includes just the name (not the path as well) of the currently assigned bitmap--you'll need to confirm this is true.
06/02/2006 (9:06 am)
For one you need a semi-colon after the line:FirstAmmoHud.getBitmap = %curBit
Second, the logic of that statement appears completely off--you appear to be wanting to use a get accessor method to assign a value, but instead are assigning a value to a dynamic field called getBitMap--and that value is always going to be empty since %curBit has never been defined prior to it's use in this scope.
A guess at what you really want here is something like:
%curBit = FirstAmmoHUD.getBitmap();
--that assumes that getBitmap() is an available method on the FirstAmmoHUD's namespace, and in fact returns a string that includes just the name (not the path as well) of the currently assigned bitmap--you'll need to confirm this is true.
#15
function changeAmmo(%val){
//%val indicates keypress state, using "if (%val){....} else return;" causes
//changeAmmo to be called once per keypress.
if (%val){
//$curBit stands for current Bitmap. For some reason local (%) isn't
//working but global is.
//1 = Blue, 2 = Yellow, 3 = Red. Counter Begins at 0 and Red is default
$curBit +=1;
if ($curBit $= "1"){
FirstAmmoHUD.setBitmap("Assignment3/client/ui/blueAmmo");
NextAmmoHUD.setBitmap("Assignment3/client/ui/redAmmo");
LastAmmoHUD.setBitmap("Assignment3/client/ui/yellowAmmo");
} else if ($curBit $= "2"){
FirstAmmoHUD.setBitmap("Assignment3/client/ui/yellowAmmo.png");
NextAmmoHUD.setBitmap("Assignment3/client/ui/blueAmmo.png");
LastAmmoHUD.setBitmap("Assignment3/client/ui/redAmmo.png");
} else if ($curBit $= "3"){
FirstAmmoHUD.setBitmap("Assignment3/client/ui/redAmmo.png");
NextAmmoHUD.setBitmap("Assignment3/client/ui/yellowAmmo.png");
LastAmmoHUD.setBitmap("Assignment3/client/ui/blueAmmo.png");
$curBit -=3; //This returns counter to zero
}
} else return; //this disallows a second keystroke on "key release"
}
//Keybind "Q" to changeAmmo function
moveMap.bind(keyboard, "q", changeAmmo);
I had to make curBit a global variable, it doesn't work as a local.
06/03/2006 (8:12 pm)
Thanks for getting back to me. I spent some time massaging it and this ends up working:function changeAmmo(%val){
//%val indicates keypress state, using "if (%val){....} else return;" causes
//changeAmmo to be called once per keypress.
if (%val){
//$curBit stands for current Bitmap. For some reason local (%) isn't
//working but global is.
//1 = Blue, 2 = Yellow, 3 = Red. Counter Begins at 0 and Red is default
$curBit +=1;
if ($curBit $= "1"){
FirstAmmoHUD.setBitmap("Assignment3/client/ui/blueAmmo");
NextAmmoHUD.setBitmap("Assignment3/client/ui/redAmmo");
LastAmmoHUD.setBitmap("Assignment3/client/ui/yellowAmmo");
} else if ($curBit $= "2"){
FirstAmmoHUD.setBitmap("Assignment3/client/ui/yellowAmmo.png");
NextAmmoHUD.setBitmap("Assignment3/client/ui/blueAmmo.png");
LastAmmoHUD.setBitmap("Assignment3/client/ui/redAmmo.png");
} else if ($curBit $= "3"){
FirstAmmoHUD.setBitmap("Assignment3/client/ui/redAmmo.png");
NextAmmoHUD.setBitmap("Assignment3/client/ui/yellowAmmo.png");
LastAmmoHUD.setBitmap("Assignment3/client/ui/blueAmmo.png");
$curBit -=3; //This returns counter to zero
}
} else return; //this disallows a second keystroke on "key release"
}
//Keybind "Q" to changeAmmo function
moveMap.bind(keyboard, "q", changeAmmo);
I had to make curBit a global variable, it doesn't work as a local.
#16
Sorry for using this old thread. Should i have made a new thread? What would yall prefer?
i'm having problems binding the command 'CursorOn();' because after it works and the mouse pointer appears it becomes difficult to use the 'CursorOff();' command successfully.
see i would like the mouse cursor to be always on -except when the user presses and holds down the right mouse button. This works successfully as it is, but when the two cursor commands are uncommented it results in the cursor always being on and the right mouse button useless.
He figured out how to make the cursor appear by editing \GameThrii\client\ui\playGui.gui and changing noCursor to "0". But that makes the cursor appear from the very beginning and our right click code doesnt work.
02/15/2008 (1:56 pm)
Hi.Sorry for using this old thread. Should i have made a new thread? What would yall prefer?
i'm having problems binding the command 'CursorOn();' because after it works and the mouse pointer appears it becomes difficult to use the 'CursorOff();' command successfully.
moveMap.bind( mouse, button1, button1Clicked );
function button1Clicked(%val) {
if (%val) {
// CursorOff();
moveMap.bind( mouse, xaxis, rotateCameraHorizontal);
moveMap.bind( mouse, yaxis, rotateCameraVertical);
moveMap.bind( mouse, zaxis, zoomCamera);
}
else {
moveMap.bind( mouse, xaxis, NULL );
moveMap.bind( mouse, yaxis, NULL );
moveMap.bind( mouse, zaxis, NULL );
//CursorOn();
}
}see i would like the mouse cursor to be always on -except when the user presses and holds down the right mouse button. This works successfully as it is, but when the two cursor commands are uncommented it results in the cursor always being on and the right mouse button useless.
He figured out how to make the cursor appear by editing \GameThrii\client\ui\playGui.gui and changing noCursor to "0". But that makes the cursor appear from the very beginning and our right click code doesnt work.
Torque Owner Teck Lee Tan
myMap.bindCmd(input device, actual input, function on key down, function on key up);