aspizu / goboscript

goboscript is the Scratch compiler
https://aspizu.github.io/goboscript
MIT License
76 stars 14 forks source link

variables and lists 'for all sprites' get reset upon initialization #46

Open rens2 opened 1 day ago

rens2 commented 1 day ago

Currently, variables and lists 'for all sprites' need to be defined in the stage while also being under a hat block like this:

costumes "blank.svg";

onflag {
    x = 0;
    delete list;
}

Unfortunately, this means that both of them are automatically reset when a project is restarted. It also interferes with scripts in other sprites that make use of these variables and lists right after the green flag is clicked, resetting them after a value has already been set or an item has already been added.

I've been able to resolve this issue with a simple workaround, but this doesn't appear to be intended behavior:

costumes "blank.svg";

onloudness > 999 {
    x = 0;
    delete list;
}

Maybe this could be solved by adding new syntax? Or, alternatively, changes could be made to allow blocks to exist without a hat block, however that does not sound like a great idea to me. Using the workaround I found is not a huge inconvenience, but it did take me some time to figure out why my project wasn't working...