scriptTickObject - anybody using this yet?
by Gibby · in Torque 3D Professional · 02/01/2013 (8:55 am) · 18 replies
Greets all...
...I've been looking at the new scriptTickObject class and think it may be useful in my AI designs. I'm curious, is anybody using this yet, and if so for what and how? Or anybody care to share a theoretical example???
...I've been looking at the new scriptTickObject class and think it may be useful in my AI designs. I'm curious, is anybody using this yet, and if so for what and how? Or anybody care to share a theoretical example???
#3
02/01/2013 (9:29 am)
It makes for a nifty automatic game state machine. Simple applications for use can be for an AIManager, game condition trigger, or even a message router.
#4
02/01/2013 (9:30 am)
@Michael, I plan to use it as an 'AIManager' curious to see an example of it using callbacks, if one exists....
#5
02/01/2013 (9:35 am)
Check out Dave's Marble Motion demo available on his blog where he talks about LeapMotion support.
#6
02/01/2013 (12:16 pm)
Ooh, this might be good for render to texture.
#7
02/01/2013 (12:48 pm)
@Michael, et al: Thanks guys it is exactly what I hoped it would be. THIS is why I've stayed with Torque all this time...
#8
NOTE: If you're not needing this high of tick precision and just want an interval timer that occurs a few times per second or a few times per minute even then please use schedule() or %obj.schedule() instead for performance reasons.
02/03/2013 (11:07 am)
Here I wrote up a script code body for those who want to use ScriptTickObject right away:// Determine if GameTicker already exists. If not create it.
if(!isObject(GameTicker))
{
// Create script tick object, name it GameTicker, and enable ticks.
%tickObj = new ScriptTickObject(GameTicker);
%tickObj.setProcessTicks(true);
// Don't forget to cleanup after mission ends if %tickObj is created on each
// mission load or in any other cases when it's intended only to exist during
// missions/levels interaction. Else it will still continue after mission end.
MissionCleanup.add(%tickObj);
}
/**
Function that is called every frame, but only if the object is set to process
ticks via ScriptTickObject.setProcessTicks(true).
Arguments:
S32 %this ScriptTickObject object instance.
F32 %timeDelta Time delta in seconds.
*/
GameTicker::onInterpolateTick(%this, %timeDelta)
{
}
/**
Function that is called once every 32 milliseconds if this object is set to
process ticks via ScriptTickObject.setProcessTicks(true).
Arguments:
S32 %this ScriptTickObject object instance.
*/
GameTicker::onProcessTick(%this)
{
}
/**
Function that is called every frame regardless if ScriptTickObject is set to
process ticks, but only when ScriptTickObject.callOnAdvanceTime = true.
Arguments:
S32 %this ScriptTickObject object instance.
F32 %timeDelta Time delta in seconds.
*/
GameTicker::onAdvanceTime(%this, %timeDelta)
{
}NOTE: If you're not needing this high of tick precision and just want an interval timer that occurs a few times per second or a few times per minute even then please use schedule() or %obj.schedule() instead for performance reasons.
#9
I've already begun using this extensively, as it opened up some ideas I'd been knocking about, hope to share soon...
02/12/2013 (12:33 am)
@Nathan: Thanks for sharing this...I've already begun using this extensively, as it opened up some ideas I'd been knocking about, hope to share soon...
#10
02/12/2013 (8:40 am)
So what is it for? running your own little VM on an object?
#11
Actually, it just occurred to me that this would be nifty for handling updates when animating gui controls.
02/12/2013 (9:53 am)
For handling something that you want to happen with fairly high frequency - this just happens to be handy for AI updates and thing like that - where the extra overhead of using the schedule() function so often starts to become noticeable.Actually, it just occurred to me that this would be nifty for handling updates when animating gui controls.
#12
I have it controlling units of AI with little extra overhead [as Richard pointed out] and now I'm adapting it as a virtual referee for a ball-based gametype ...
02/12/2013 (9:57 am)
@Kyrah: Yeah, like that...I have it controlling units of AI with little extra overhead [as Richard pointed out] and now I'm adapting it as a virtual referee for a ball-based gametype ...
#13
02/13/2013 (12:39 am)
The onInterpolateTick and onAdvanceTime callbacks are a bit scary. You don't want to be running script functions every frame.
#14
02/13/2013 (8:32 am)
@Guy - Excellent point, one must proceed with caution... I'm finding that by using the one scriptTickObject was a better tradeoff than multiple, singular AIs ticking away...
#15
The reason I mention this is because I could see this object causing something similar. Although, every feature that gives you power, must be tempered by wisdom. ;)
Now, I am confused as to why you would use this for AI. I thought AI had a onThink or Think callback?
02/13/2013 (12:34 pm)
I tried something like but using threads. I have a thread grabbing data and I thought I could call a script function every 50mS. The script call code can handle that because it checks to see if it is in the main thread or not. If not it schedules a call in the main thread. However, after a while it hoses the timing on the main thread somehow. This results in a fatal assert failure of some sort. So don't do this from outside the main thread!The reason I mention this is because I could see this object causing something similar. Although, every feature that gives you power, must be tempered by wisdom. ;)
Now, I am confused as to why you would use this for AI. I thought AI had a onThink or Think callback?
#16
Props to the guys who wrote the AI kits that are available; I have tasted the fountain of pain from whence you drank.
02/13/2013 (4:19 pm)
Oh, T3D AI has a WishICouldThink callback. The default mechanisms are crazy bare-bones. I did some work to try to give new users somewhere meaningful to start when implementing some sort of rudimentary AI and it was quite a chore. And it still stinks.Props to the guys who wrote the AI kits that are available; I have tasted the fountain of pain from whence you drank.
#17
02/14/2013 (9:24 am)
@Frank: There isn't an 'onThink' in T3D's stock AIPlayer, thus some sort of behaviour must be scripted for it to work. I'm using this class as a 'unit' controller' that thinks for a large group of AI agents, the idea being the use of one scriptTickObject is more efficient than two dozen separate AIs ticking away...
#18
02/14/2013 (11:13 am)
I'm with Gibby on this. I used a manager object to tell the individual units when to think so that I could have better control over the resources being used. My solution didn't use such fine granularity since a unit would react immediately to damage.
Torque Owner Richard Ranft
Roostertail Games