[Closed] Recovering MaxScript after error in Structure declaration
Sometimes, when declaring Structures, I make the mistake of adding a “=” as in functions.
As expected, it throws a syntax error:
struct myStruct =
(
a, b, c
)
-- Syntax error: at =, expected (
After that, MaxScript seems to be messed up and I get compile errors in any other script I attempt to run, even if I fix the structure, there seems to be no way to keep working until I restart Max.
-- Compile error: Undeclared variable:
Is there a way to fix this issue without restarting Max?
In Max 2011-2012, if I remove the “=” symbol then I can declare the Structure again without error. However, if I create a new Script or try to run some other ones I get different errors. For example:
Max 2012
(
fn test =
(
return true
)
)
-- Compile error: Undeclared variable: test
(
local a = 2
)
-- Runtime error: Bad local thunk local member index when accessing local: a
Max 2011
(
local a = 2
)
** system exception **
i see it now. really weird… i can’t find anything to fix it without reloading max. that’s mxs bug for sure.
Interesting, works without glitches both on 2014 w/ extension and 2015 w/ extension. Even tried some basic blunders (mismatched brackets, if-then without semicolon/else in the listener) to no avail, couldn’t force it to misbehave the way it used to.
Looks like maxscript still “hangs” somehow in the first, faulty struct definition ( the one with the wrong “=” )
You can check that as you will get a “** interrupted **” each time you enter something and hit ESC afterwards. Somehow the listener still expects you to complete the struct definition, and apparently is in some faulty state caused by the errornous definition.
Means to complete and close the definition would be necessary, but that as well might be impossible via the listener in that situation…
EDIT:
seems maxscripts still is stuck in the local scope of the faulty struct. You can create, access and manipulate global variables ( eg. using :: syntax or global ) but without that, all variable names are interpreted as struct members
It’s probably not related but here’s a tip I use a lot when code has run but I forgot to close a scope properly, or at least think I did.
In the listener type: )
then numeric enter a few times, usually the error pops up after that, because somehow I feel maxscript was stuck in a loop waiting for the script to end but the closing ) was never found. Maxscript returns to normal after that, but I do have cases of weird hangs, especially after lots of runs when working on a script, and the only way to recover is a restart.
-Johan