Error: Scrip has exceeded its maximum running time

I made an AI for my chess game using the MinMax algorithm to generate a decision tree. If I set the depth value for the tree generation to 1, it works, because the tree only has like up to 50 nodes. But if I go any deeper and it has to do 1-1000 nodes, all the verse code in the map stops working it seems and I get this error:
Error: Scrip has exceeded its maximum running time

In short, is there a fix that will allow me do to more intense computations?

The function if you are interested:


Looking at the code one option you have is to manually time-slice your script. Since this is a suspends function you could try sleeping inside the for loop after N iterations.

For example:

for (I->Piece : Board.Pieces):
    # do some computation
    
    # If index I perfectly divides by 100 sleep for a frame
    if (Mod[I, 100] = 0):
        Sleep(0.0)
4 Likes

WHAT A COINCIDENCE, I just tried the same thing and it works. Do you know why this works becaues I dont really understand how this fixes it?

Verse has internal checks that try to prevent scenarios where you can do things like infinite loops, super long processing, etc. This is how we ensure that a bad script cannot completely ruin the user experience or lock up the server. By adding a sleep to this code you are yielding back execution for other Verse code to run. This also has the effect of resetting those internal “too long to process” counters for your code.

3 Likes

I get the same excesive computation error on this single line of code. Any idea how you would timeslice this?

TaggedBlocksL:[]creative_object_interface := GetCreativeObjectsWithTag(grassblocktag{})

In my map I have 15,000 props, 10,000 of them are tagged with the tag grassblocktag

I ran into this too, but I only had about 450 props and prop movers tagged. I reduced it down below 400 for each and it worked ok after that. I assumed it had something to do with too many prop movers and just moved on. I’d be curious if you found a solution to this.

1 Like

My guess is you’ll probably need to split your props into a bunch more different tags instead of having them all use one tag, (and maybe Sleep(0.0) between each call to GetCreativeObjectsWithTag)

@JoeriDukker

In this circumstance there isn’t much you could do as it is the underlying Verse function you’re calling that is timing out. As a few other users have pointed out, you could go and re-tag content so that you have fewer matches. Then you could request groups of things one tag at a time.

I also reported the timeout problem internally to get more eyes on it. I can’t report on any long term solutions or future language changes. However, in the short term we’re going to be extending the timeout duration for Verse scripts. This should greatly reduce the amount of times people hit this brick wall. That change should be rolled out very soon, assuming it hasn’t already been released.

1 Like

That is amazing, I do have to timeslice my code quite often, for example with chess, or looping over 15k actors.