BakkesModPlugins icon indicating copy to clipboard operation
BakkesModPlugins copied to clipboard

While Loop causes game crash

Open TaylorSasser opened this issue 8 years ago • 4 comments

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

TaylorSasser avatar Nov 22 '16 04:11 TaylorSasser

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.

Bakkes avatar Nov 22 '16 09:11 Bakkes

thanks :D

TaylorSasser avatar Nov 22 '16 17:11 TaylorSasser

Would it be possible to paste some pseudo code with the setTimeOut method? I cant figure out how to use it in my plugin.

TaylorSasser avatar Nov 22 '16 22:11 TaylorSasser

Check the defender plugin: https://github.com/Bakkes/BakkesModPlugins/blob/master/DefenderPlugin/DefenderPlugin.cpp#L76

ivanfeli avatar Nov 22 '16 22:11 ivanfeli