Random Error Message

Sora574
Okay so here's the problem...
I was working on my stackable library, going about my business. Then, I finished it and decided to test it.
I tested every possibility inside and out and I couldn't find any problems until I started using the 'use' command to unstack specific objects. Then, Quest would throw a random error saying: "Error running script: Collection was modified; enumeration operation may not execute." However, the script works -- it just throws out a pointless error.

It might be the demo, but I'm almost positive it's the library.

Either way, the library is in this topic
The demo is here:

Can anybody see what's wrong?

jaynabonne
This is a fundmental design consideration with Quest, and not a bug as such: you cannot modify a list while it's being enumerated with foreach. In your case, you are executing "foreach" in function use_container. Inside this foreach loop, you invoke "useinstack" on the object which destroys itself when done. When you destroy an object, Quest automatically sets all references to it to null and removes it from all containers that contain it. So it is removed from the list which still has an active "foreach" going on.

When the foreach resumes, it throws the error.

It might seem like it's working, but the foreach actually terminates at that point (and probably all code after it).

There are a few ways around this, but they all involve changing your design slightly. Either the object shouldn't destroy itself, or the loop you use can be changed to a for loop, executing over the items in a different way. Or objects which are meant to be destroyed get moved to a holding place, which is then destroyed later. Or perhaps something else...

But touching a list while it's being enumerated is a no-no.

Sora574
Hmm... Well I tried to just move objects to a different location and it didn't work. It says the same thing

jaynabonne
Sorry I didn't reply to this sooner... Would you be able to post that changed file here? Thanks!

Sora574
Mkay first... Sorry it took so long for me to reply. I've been doing stuff, and I finally have time for me now lol.

And apparently that time away refreshed my ideas because I took one look at the library and realized that half the stuff in the foreach in the use_container doesn't need to be there. I just moved it to outside of the foreach and it works perfectly now (as far as I know.)

I should be publishing the new library tomorrow. Here's a sneak peek, though, if you want to test it out.



Anyways, thanks for the help.

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums