delayin execution of script ?

ABK

Well-known member
Whats the syntax and command to delay a script execution, i have key inputs and after it will detect key input i want it to wait before performing velocity change.
How would i do that ?
I need it cause to make key inputs detection work best i need delay1 and with delay1 velocity change is immediate all the time, its kinda insane, so i need something to introduce delay so when i press left or right, velocity change will be applied after lets say half second.
Its very easy to do in godot  where i would just put command before velocity change and engine would not go to velocity change until that first delay command was finished, but in openbor i dont think i encountered such scripts.
I suspect its super easy in openbor and its just my noobhour at its best.

Code:
		@script
                void self = getlocalvar("self");
				 int sped = getentityproperty(self, "speed");
                int iPIndex = getentityproperty(self,"playerindex"); //Get player index
                void a1 = playerkeys(iPIndex, 0, "jump");
                 void d1 = playerkeys(iPIndex, 0, "movedown");
                 if ( a1 &&  openborvariant("elapsed_time")+2000  ){
				                  openborvariant("elapsed_time")+2000 ;
                changeentityproperty(self, "velocity", 0 ,-sped);
		}
		           if ( !a1 ){
				                    openborvariant("elapsed_time")+2000 ;
                changeentityproperty(self, "velocity", 0 ,0);
		}
		 if (( d1 )&&(a1)){
		                  openborvariant("elapsed_time")+2000 ;
                changeentityproperty(self, "velocity", 0 ,sped);
		}
	@end_script


This would get me delay in godot before executing music play, do we have something like this in openbor ?
Code:
  yield(get_tree().create_timer(0.5), "timeout")
    $Music.play()
 
bWWd,

OpenBOR doesn't have native delayed callback like that.

The way to do this would be take a que from how those callback systems work internally, and also how the engine does internal timing. Set a global variable to current elapsed time + your desired delay value. Then, in an another script (usually an update or time tick) you compare your set time to elapsed time. When elapsed time catches up to your set time, you perform the action and delete the time variable.

If you aren't super worried about time accuracy, timetick is slightly better than update since you are only running the time check on each tick of the clock. Update is the most accurate, but more resource consuming. That said, time comparisons are very fast. The engine is loaded with these, and I mean loaded - from animation delays to pause effects, virtually everything timing related depends on them. Don't worry too much about it slowing your module down. Again, it's how those native delayed executions work anyway.

If you want to get extra fancy, OpenBOR does have an oft forgotten ability to force execution of a script - so you would only need to have the timer code in update/time tick, while the action code remains wherever you have it now. That's just an option though, it's not necessary or any difference in efficiency. Just something you might be interested in from a code organization standpoint.

DC

 
Ah, so thats what i was worried about, i need it for 4 players and for left/right, thats a lot of variables to take care of for simple task.
Will we get this kind of delayed callback in the future updates ? I remember i needed it for freeze unfreeze before and it would definitely be useful for me, not sure how others feel about it.
As for today i guess i have to do it the convoluted way with variables.
Would entityvar be better for this ? Also new key input would override previous keyinput variable for timing,  i need to figure out how many vars i need per player ,i dont think i have head for this.Id have to see example cause its not just one button, its for car racing stage like micro machines.My car just spins around immediately when pressing left/ruight and i need to find a way to slow this down.
 
Back
Top Bottom