GG: question about RTSUnit schedule()
by Stephen Zepp · in RTS Starter Kit · 11/20/2004 (9:16 am) · 2 replies
Is this somehow disabled? I can't find any indictations that it is, and it does show in a client side .dump() of an RTSUnit, but for the life of me I cannot get a schedule on an RTSUnit to process.
This works, with %this being a valid server side RTSUnit:
The event is scheduled, and processes every 5 seconds (it reschedules itself).
However, this does notwork:
Note that the overloaded format for %objectId.schedule() removes the second parameter (%this) in normal operations.
This works, with %this being a valid server side RTSUnit:
function repeatingAddSupplies(%this, %scheduleTime, %store, %requestId, %request, %notifyClient)
{
echo("repeatingAddSupplies()\n---%this:" SPC %this SPC "\n---Schedule:" SPC %scheduleTime SPC
"\n---%store:" SPC %store SPC "requestId: " SPC %requestId SPC
"\n---request: " SPC %request SPC "Notify Client?" SPC %notifyClient);
// do the command
resourceStore::requestAddSupplies(%this.client, %store, %requestId, %request, %notifyClient);
// reschedule
%this.supplyAddEventId = schedule(%scheduleTime, %this,
"repeatingAddSupplies", %this, 5000, LOCAL, ScheduledRepeatingSupplyAdd, "GOLD 50", false);
echo("resourseStore::repeatAddSupplies rescheduled, id is (" @
%this.supplyAddEventId @ ")");
}The event is scheduled, and processes every 5 seconds (it reschedules itself).
However, this does notwork:
function repeatingAddSupplies(%this, %scheduleTime, %store, %requestId, %request, %notifyClient)
{
echo("repeatingAddSupplies()\n---%this:" SPC %this SPC "\n---Schedule:" SPC %scheduleTime SPC
"\n---%store:" SPC %store SPC "requestId: " SPC %requestId SPC
"\n---request: " SPC %request SPC "Notify Client?" SPC %notifyClient);
// do the command
resourceStore::requestAddSupplies(%this.client, %store, %requestId, %request, %notifyClient);
// reschedule
%this.supplyAddEventId = [b]%this[/b].schedule(%scheduleTime, "repeatingAddSupplies", %this, 5000,
LOCAL, ScheduledRepeatingSupplyAdd, "GOLD 50", false);
echo("resourseStore::repeatAddSupplies rescheduled, id is (" @
%this.supplyAddEventId @ ")");
}Note that the overloaded format for %objectId.schedule() removes the second parameter (%this) in normal operations.
#2
Quick question though (I've got this working with the global schedule now, so it's not critical, but for others that may rely more heavily on a scheduled repeatingAddSupplies)--when we create the function, do we still want it called 'repeatingAddSupplies', or should we call it 'RTSUnit::repeatingAddSupplies'?
Thanks!
11/20/2004 (9:52 am)
Great info Pat, thanks a ton! And yep, that would explain the problem. I originally defined the function as resourceStore::repeatAddSupplies but that didn't work in either mode (schedule or %this.schedule), so I made it repeatAddSupplies, and you are correct, that worked fine since it found it globally.Quick question though (I've got this working with the global schedule now, so it's not critical, but for others that may rely more heavily on a scheduled repeatingAddSupplies)--when we create the function, do we still want it called 'repeatingAddSupplies', or should we call it 'RTSUnit::repeatingAddSupplies'?
Thanks!
Torque 3D Owner Pat Wilson
The problem is that the format '%this.schedule( %time, %function, ... )' is for use with script methods, not regular functions. (Method being a member-function of an object).
When that executes, it's going to try to call '%this.repeatingAddSupplies' and even though TorqueScript doesn't have a real concept of 'this' like C++ etc does, that could be the reason for failure. If you want to do it that way, it should look like this:
Now repeatingAddSupplies is considered a member function of RTSUnit.
The reason the first one works is because you are manually passing %this as an argument, and when schedule failed to call the function on the object, it called it as a global function, and succeeded.