Game Development Community

Passing functions in schedule()

by Tim Doty · in Torque Game Builder · 03/16/2005 (3:46 pm) · 5 replies

This derives from the OO resource, but AFAICT it is really a TorqueScript question. If a class has a function then passing that function in schedule() doesn't seem to be possible:

schedule(2000, 0, "%this.Show","");

This results in looking for a function literally named "%this.Show" which of course doesn't exist.

schedule(2000, 0, %this @ ".Show","");

This results in looking for a function named "1242.Show" (varies by handle number, of course) which doesn't exist.

schedule(2000, 0, "myClass::Show","");

This still results in the function not being found though I'm not sure why as the name is correct.

schedule(2000, %this, "myClass::Show","");

Does not result in an error, but nothing happens (schedule returns 0 in this case which by my reading of the function source means it was unable to resolve the object).

Incidentally, issuing %this.Show() in a function works fine so it isn't an issue with the function itself it is how functions are passed in schedule().

Am I trying to use TorqueScript in ways its not intended? Or what am I doing wrong?

#1
03/16/2005 (3:50 pm)
%this.schedule(1000, "function", arg1, arg2, argn);
#2
03/16/2005 (3:50 pm)
You can also use a local schedule rather than a global one eg.

%this.schedule( .... )

or

$player.schedule( ..... )

Not sure if that will help out or not, also you may need to pass %this as a parameter to the end of the schedule command. I'm sure someone with more scripting knowledge will help, but till then give the above a shot.
#3
03/16/2005 (3:56 pm)
Thanks very much, both of you. I've got that sorted out now. It hadn't occurred to me that schedule could be called in the object's context and that does exactly what I need. And no need to pass %this, it is still implicit.
#4
03/17/2005 (7:31 am)
Glad you already got it working, there is a reference to the schedule command in the FAQ as well that might help :)

num #30

Torque 2D Unofficial FAQ
#5
03/17/2005 (10:11 am)
The only problem with the documentation (and I have a fair amount printed out for reference) is that it is segmented and disorganized. Already a known issue, I know, but that is why questions keep coming up.

Thanks again for all the pointers.