Daemian Wrote:Hey, wait, I found another way to loop a function without timers!
This seems to be looping once every 0.01 seconds. (100 times per second)
Is that an acceptable number for your game Behe? Or you need it to loop faster?
I'm editing in a second with the code in case you wanna give it a try.
Basically it's an entity jumping from one area to another.
The areas fire a collide callback, throwing the object from area A to area B in a constant loop.
This process -according to tests- takes about to one unit of a second. (I can see the debug messages increasing by 100 every second). So it's fast, and kinda light to process too.
So, two areas and one entity.
You declare the entity callback on both areas, and use
PlaceEntityAtEntity to send the object to the other area.
That will loop, and you can use the function to run your things.
Here's the code:
void OnStart ()
{
AddEntityCollideCallback( "Area1", "EntityX", "LoopFunction", true, 1 );
AddEntityCollideCallback( "Area2", "EntityX", "LoopFunction", true, 1 );
}
void LoopFunction ( string &in sArea, string &in sEntity, int iState )
{
if ( sArea == "Area1" ) {
AddEntityCollideCallback( "Area2", sEntity, "LoopFunction", true, 1 );
PlaceEntityAtEntity( sEntity, "Area2", EMPTY, true );
}
if ( sArea == "Area2" ) {
AddEntityCollideCallback( "Area1", sEntity, "LoopFunction", true, 1 );
PlaceEntityAtEntity( sEntity, "Area1", EMPTY, true );
}
//UpdateGruntsAnimation();
//UpdateOtherThing();
//UpdateJumpingStuff();
}
You gotta hide these two areas and entity in your maps, somewhere safe from the action.
What else? I attached the entity I'm using, it has no gravity, no collision, nothing. Just what it needs to make this work.
Mmmmh Am I missing something? Anyways, there it is, I hope you like it.