Basic RPG control
by Daniel Stirk · in Torque Game Builder · 10/05/2005 (5:57 am) · 1 replies
I've got a big dilema. We're making an RPG game in T2D, and waiting for the player to press a button before going to teh next line of text is a problem.
We don't want to pause the scene. NPCs should still be walking around teh screen, so pausing the entire engine is not a valid solution at the moment.
Here's the more detailed explaination. We tried binding functions to one key. WHen that key is pressed, it calls a function and we rebind it to another. This leads to way too many functions, and different NPCs will have their own set. THerefore, we concluded that storing a list of commands in an array is the best course of action.
However, this led to problems. We can't run a scedule command using a command in this array. We store strings in this array, but sceduling something like schedule(2000, %command) fails horribly. So, this is what we enede up doing so far....
What this is doing is binding a string list of commands to a button. The character, $jack, walks north, and then stops. When g is pressed it runs the commands. THe reason for popping and scheduling a push for the action map is so that the player cannot spam the button and keep scheduling this stuff.
Now, it seems to work okay, and we can make a function that is also called at teh end of this which binds another action, preferably another in an array, like from %command[1]. This way, we can have a class that will control the player's actions and we can step through a list of commands.
Now, this leads to another problem. We can't use any local variables here, so anything we pass it has to be stored in a global variable or static function. That means that all NPCs have to be global variables if we want to access them. We can't do that, since it will break our existing structure.
So, any one have an idea of how to have a list of commands run and step through them with an action button? Would greatly appreciate the help.
We don't want to pause the scene. NPCs should still be walking around teh screen, so pausing the entire engine is not a valid solution at the moment.
Here's the more detailed explaination. We tried binding functions to one key. WHen that key is pressed, it calls a function and we rebind it to another. This leads to way too many functions, and different NPCs will have their own set. THerefore, we concluded that storing a list of commands in an array is the best course of action.
However, this led to problems. We can't run a scedule command using a command in this array. We store strings in this array, but sceduling something like schedule(2000, %command) fails horribly. So, this is what we enede up doing so far....
%command[0] = "nextcommand.pop();$jack.goNorth();$jack.schedule(2000,stop);nextcommand.schedule(2000,push);"; new ActionMap(nextcommand); nextcommand.bindCmd(keyboard, "g", %command[0], ""); nextcommand.push();
What this is doing is binding a string list of commands to a button. The character, $jack, walks north, and then stops. When g is pressed it runs the commands. THe reason for popping and scheduling a push for the action map is so that the player cannot spam the button and keep scheduling this stuff.
Now, it seems to work okay, and we can make a function that is also called at teh end of this which binds another action, preferably another in an array, like from %command[1]. This way, we can have a class that will control the player's actions and we can step through a list of commands.
Now, this leads to another problem. We can't use any local variables here, so anything we pass it has to be stored in a global variable or static function. That means that all NPCs have to be global variables if we want to access them. We can't do that, since it will break our existing structure.
So, any one have an idea of how to have a list of commands run and step through them with an action button? Would greatly appreciate the help.
About the author
Torque Owner Tim Doty
Instead of removing the action map why not use a flag to indicate the function has already been called? I'm thinking along the lines of:
function someCommand() { if ($commandFlag == true) return; $commandFlag = true; // do some stuff $commandFlag = false; return; }If you want to only allow one command to be queued you can do that with a single flag.
function scheduleCommand(%command) { if ($jack.commandQueued == true) return; $jack.commandQueued = true; $jack.schedule(2000,"startCommand",%command); } function startCommand(%command) { $jack.commandQueued = false; eval(%command); }If you want to allow queuing of more than one command I'd use a FIFO structure. I have a fondness for linked lists and would probably implement it that way, but you could also use an array.
As to using global variables for the NPCs, you say it will break your existing structure. I'm not sure I follow because if they aren't global then in what scope are they available? Inside of some function only?