Game Development Community

Doing things 'once per loop

by Skitchy · in Torque Game Builder · 02/22/2006 (12:28 am) · 5 replies

You'll have to excuse the noobness of this post, but I've been programming in Basic forever, and have become accustomed to the linear way in which it works.
In T2D, say you have a projectile called %p. Now, you want to do something to %p every 'engine loop'.

In Basic, I'd do something like this (pseudo-code)

repeat
updateprojectile(%p)
forever

function updateprojectile(%input)
do stuff to input
end function

What is the equivelant way of achieving this in TorqueScript?


Suppose %p was a homing missile and it needed to change color based on its proximity to %q. I'd need to check this proximity and alter the color on a regular basis.

#1
02/22/2006 (12:58 am)
You could use the schedule command to call updateProjectile every half second or so, not sure how you would change the color though.
#2
02/22/2006 (3:01 am)
Surely there MUST be a way of doing this. How else would you do realtime AI for example? Or change the reactions of a simple enemy based on the player coordinates?
Doesn't each object have a function that it calls once per cycle by default?

If not, I've noticed a set of 'timer' functions as well as 'schedule'. How would you set up a timer to call a function once per cycle? Is it a viable option, or will it slow the whole thing down?
#3
02/22/2006 (3:02 am)
Or you could call your update function in onUpdateScene. If you are likely to have loads of projectiles that you will need to update, you might be better off setting the timer for each projectile and when it goes off, you call your update function.

You'd change the colour either by changing the sprite to one that has different colouring, or by calling setBlendColor (is that still the right name for it in the current release?) and manipulating it's RGB properties.
#4
02/23/2006 (3:49 am)
I'd forgotten about onUpdateScene. I might use that on something i'm doing now :)
#5
02/23/2006 (4:00 am)
function myThingy::myFunction(%this)
{
//.... code here
%this.schedule(50,%this,myFunction); // Call this over and over every 5 seconds.
}