BakkesModPlugins
BakkesModPlugins copied to clipboard
While Loop causes game crash
I had the code
while(car.isOnGround() == true) { ball.getLocation().X , Y, Z print out ball location to ingame log }
inside my plugin that was executed on the onCommand event. This causes the game to crash :P
I recommend having something that is some kind of way of doing a onClientTick method, so everything is in sync between the game & plugin
You're inserting an infinite loop that gets executed while inside a game tick, hence it crashes, what you're doing now is blocking the main game thread. It is possible to execute a piece of code using the setTimeOut method, with a timeout of 0 ms, this will allow you to execute code every gametick. Change the while to an if statement and use the setTimeOut method, then it should give you your desired behavior.
In a next release I might add an onClientTick method, but for now you need to use a timeout with 0 ms.
thanks :D
Would it be possible to paste some pseudo code with the setTimeOut method? I cant figure out how to use it in my plugin.
Check the defender plugin: https://github.com/Bakkes/BakkesModPlugins/blob/master/DefenderPlugin/DefenderPlugin.cpp#L76