Constant Gui Update
by __._ · in Torque Game Engine · 08/17/2007 (6:00 am) · 8 replies
At the moment I'm trying to make a compass, so I will have to update my playgui as soon as the player moves or just every second.
Has anybody an idea how to do this ? tnx
Has anybody an idea how to do this ? tnx
#2
So I'm trying to find a way to fix it with scripting.
08/17/2007 (6:44 am)
Well.. the problem is I don't have the sdk version. They handed over a compiled version to me with the question to finish a game ( kindof crazy ).So I'm trying to find a way to fix it with scripting.
#3
There's more functions regarding cancelling schedules that I can't remember off the top of my head, just do a function dump in the console to find them all, but in the meantime here's a crude example that works:
Throw that in a script, run the game and type this into the console to call the function:
To stop the function from looping, type this into the console:
Type this into the console to save a list of all available console functions:
08/17/2007 (7:29 am)
If you're limited to script then you could try using a schedule to loop the function.There's more functions regarding cancelling schedules that I can't remember off the top of my head, just do a function dump in the console to find them all, but in the meantime here's a crude example that works:
new ScriptObject(Compass)
{
class = CompassGUI;
loop = true;
};
function CompassGUI::doStuff(%this)
{
// Your code here
error("bla " @ %this);
if (%this.loop)
%this.schedule(100, "doStuff", %this);
}Throw that in a script, run the game and type this into the console to call the function:
CompassGUI::doStuff(compassGUI);Check the console and you'll see the word bla constantly being repeated, i.e. the function is looping.
To stop the function from looping, type this into the console:
compassGUI.loop = false;
Type this into the console to save a list of all available console functions:
dumpConsoleFunctions();
#4
the only problem I seem to have now is that it only runs once. And when I remove the check of the loop,
I get this message :
Unable to find object 'compassGUI' attempting to call function schedule.
It seems like somehow I start the function, but there is no object. ( the function runs once and then gets into trouble ).
08/20/2007 (5:48 am)
Ok, Almost there!the only problem I seem to have now is that it only runs once. And when I remove the check of the loop,
I get this message :
Unable to find object 'compassGUI' attempting to call function schedule.
It seems like somehow I start the function, but there is no object. ( the function runs once and then gets into trouble ).
#5
08/20/2007 (5:52 am)
Sounds like it can't find the %this. How are you calling the function?
#6
You should be calling the function as:
And to set the loop bool:
You don't have to do it my way, with a script object and class however I'm guessing that will be easier for you in the long run as you can store information within the class.
08/20/2007 (6:00 am)
Oh dear, I made an error.You should be calling the function as:
compass.doStuff();
And to set the loop bool:
compass.loop = false;
You don't have to do it my way, with a script object and class however I'm guessing that will be easier for you in the long run as you can store information within the class.
#7
It's a pity I don't have much time to study the right syntax of Torque. They asked me to finish a game in 3 weeks. Without any knowledge of Torque or game engines, and no sdk ( the guy who was supposed to give me is on vacation ).
But got a working compass now.
I'll post the source later as a mod :)
08/20/2007 (6:37 am)
It works! Great, thanks :)It's a pity I don't have much time to study the right syntax of Torque. They asked me to finish a game in 3 weeks. Without any knowledge of Torque or game engines, and no sdk ( the guy who was supposed to give me is on vacation ).
But got a working compass now.
I'll post the source later as a mod :)
#8
In stock TGE (and TGE-A), Gui objects automatically receive a namespace based upon their name, just like ScriptObjects do. This means that you do not actually have to create a ScriptObject wrapper for your Gui object, but can simply name the Gui appropriately, and use that as your namespace.
08/20/2007 (8:21 am)
Quick note: Tim's suggestion is spot on, but he missed one minor detail that makes it a touch easier:In stock TGE (and TGE-A), Gui objects automatically receive a namespace based upon their name, just like ScriptObjects do. This means that you do not actually have to create a ScriptObject wrapper for your Gui object, but can simply name the Gui appropriately, and use that as your namespace.
Torque 3D Owner Jacob