Game Development Community

constantly calling script functions

by Jared Hoberock · in Torque Game Engine · 03/20/2002 (1:26 pm) · 8 replies

How can I get a script function to continuously call itself as soon as a player is created in game.cs?

#1
03/20/2002 (1:35 pm)
Did you try it with "schedule()"?
E.g.
function repeatDoingCoolThings()
{
	$coolnessCounter++;
	echo("Coolness factor is: " @ $coolnessCounter);
	doSomeOtherCoolThings();
        // schedule(TIME_IN_MS, OBJECT, FUNCTION, PARAMS...)
        schedule(100, 0, "repeatDoingCoolThings");
}
So this function would call itself every 100ms...
Helpful??
#2
03/20/2002 (2:01 pm)
This isn't the best way to do loops. You're much better off doing it somewhere in c++ code. If you're scripting in relation to some screen object the onRender method is a good place to constantly call some function or calculation.
#3
03/20/2002 (2:50 pm)
THe function is supposed to constantly update the value of a variable I added in the player's LightMaleHumanArmor datablock. I don't think I can modify this value in the source code; it has to be from scripts. Any other ideas?
#4
03/20/2002 (3:44 pm)
If you need to constantly update the value of an object field, you need to make it a field that is accessible from both the scripting and the engine code (with the appropriate addField invocation in the class's initPersistFields member function in the engine code).

Then have the engine code update it every time processTick is run for that class, or however often you need to update it.
#5
03/20/2002 (3:57 pm)
Also even if you couldnt access it you can run script commands from the C++ code.

Look up Con::evaluate and Con::execute

The way I would suggest you do it is to Con::execute a script function from the C++ code. This is how the callbacks in the code right now work. That way you can put whatever code you want in the script function.

-Tim aka Spock
#6
03/21/2002 (4:43 am)
You can even add a Con::Execute() in the processTick of your class. This is what I did for our plane class and it works well.
#7
03/21/2002 (4:53 am)
Plane???!!! You've got a plane in the game? One that just flies around with no need for a pilot? If so, I would really like to know how you did it. Thanks, D
#8
03/21/2002 (6:04 am)
Yep !!!
Our current game Dog of Prey is all about planes (which fly but need a pilot ;)).
Go here to have some info www.garagegames.com/mg/snapshot/view.php?qid=65