Turn based game exceeding max loop instructions

Started by Builder17, December 09, 2017, 03:04:45 AM

Previous topic - Next topic

Builder17

I am probably missing some obvious way how to fix this code. It crashes game when run.

Edit: Fixed it using lists from PAC AI.

GoodMorning

This:

999999 0 do


That's a crash by itself, without a break.
A narrative is a lightly-marked path to another reality.

Builder17

I see, thanks. That is intended to make code under it repeat forever until condition is reached, any better way to make that?

Karsten75

Quote from: Builder17 on December 09, 2017, 05:22:18 AM
I see, thanks. That is intended to make code under it repeat forever until condition is reached, any better way to make that?
Remember - each CRPL core is scheduled to run on every frame of the game - that's 30 times a second. If this one core tries to "repeat forever", then nothing else gets to run and the game won't advance another frame.

Builder17


kajacx

I use

while true repeat

endwhile

sometimes, and yes, I also often forget to break inside the loop :D Thankfully you will get the "execution limit of 1 000 000 isntruction exceeded" error that is often caused by an infinite loop, so it's not that hard to debug.
Why do work yourself, when you can write a program that will do the work for you.

Builder17

Quote from: kajacx on December 09, 2017, 09:20:42 AM
I use

while true repeat

endwhile

sometimes, and yes, I also often forget to break inside the loop :D Thankfully you will get the "execution limit of 1 000 000 isntruction exceeded" error that is often caused by an infinite loop, so it's not that hard to debug.

Sounds that this might work, thanks.

GoodMorning

Keep in mind - because CRPL for a frame needs to finish running before the game can update the screen, you have to terminate the script execution regularly.

Why not just run the inside of that loop once each frame?
A narrative is a lightly-marked path to another reality.

kajacx

Quote from: GoodMorning on December 09, 2017, 05:38:31 PM
Why not just run the inside of that loop once each frame?

Is that possible? From what I tested in PRPL, 1 Delay will technicaly sleep for 2 frames (it will stop the execution on the current frame, then sleep on the next frame, and then resume the execution on the next frame), so that your code executes only every other frame and 0 Delay does nothing.

This was quite anoyying since I needed to execute code inside a loop every frame, so I had to do it every other frame instead which had some unfortunate consequences.
Why do work yourself, when you can write a program that will do the work for you.

GoodMorning

I mean...


<-InLoop not if
#Pre
endif

<-InLoop if
#Loop body
endif

<-InLoop if return endif

#Rest of script


...but well-structured code should be able to update every frame in the natural way. Loops over multiple frames are a sign of bad code, and a Delay inside a loop can (will) break on save/load, possibly causing a crash due to stack-context clearing after :awake and :GameLoaded.
A narrative is a lightly-marked path to another reality.

Builder17

Fixed this one already, new script attached to first post!

kajacx

Quote from: GoodMorning on December 09, 2017, 07:42:02 PM
a Delay inside a loop can (will) break on save/load, possibly causing a crash due to stack-context clearing after :awake and :GameLoaded.

Hm, I never knew that. Btw your solution looks interesting, might use it if I even needed. however the one time I needed to sleep inside a loop was when I wrote the PRPL debugger, it worked by adding a function call before every single command that would possibly pause the code execution unit the user took some action.

It was real fun, but I had to listen for mouse click every single frame to catch the user clicking on a button, in the end I didn't use the "GetMouseDown" and checked the change manually with "GetMouse", however for the future I have planned key input as well to modify the stack mid - execution with arbitary commands, and doing this with key input as well will be quitre a distaster, but hey, at least it would work.
Why do work yourself, when you can write a program that will do the work for you.