Notifications
Clear all

[Closed] clear a msx session w/out restarting max?

I am debugging a script that crashes early on first run,
but crashes later (the first bug seems t go away) on a second run.

so something (a gloabl var probably) is lingering after the first run.

Is there any way to “clear” the session so the script runs like it’s the first time again, without a max restart?

8 Replies

I would love to know this as well… I also get plagued by lingering globals which, if I’m not careful, will lead me to believe the script is working on a second or third run only to find that after restarting Max, I have bugs!

if you know your globals just clean them up and run the script again…
sometimes just the fact of a global existence can make a difference… so the safer way is to remove them using globalVars.remove

[delete][delete][delete]

some experimenting has revealed globals are not my problem,
but 2 recursive functions calling each other.

the basic form is like this:


obj = <an object either type:A or type:B> 

fn fucntion_1 obj=( 
  case obj.type of ( 
    A: (<do stuff to obj>) 
    B: ( function_2 obj) 
  )
)

fn fucntion_2 obj=( 
  case obj.type of ( 
    A: ( function_1 obj) 
    B: (<do stuff to obj>) 
  )
 )

First run:
function_1 definition is incomplete and crashes
because the definition calls function_2 which is not yet defined.

Second run:
function_2 has been defined in First Run,
so function_1 can define properly.

(the reason I don’t have type A and B in one function is because in reality they are JSON data which can recursively contain either Json Objects or Json arrays, each of which must parse differently)

does this sort of thing have a common solution,
or is it simply commonly avoided by decent programmers?

functions can be used like any other variable in mxs, so to “clear” them just set them to undefined

do a forward declaration of the function ?

I fixed the problem by figuring out how to combine the 2 functions into one.

confusion recursing can lead to confusion recursing.

So just to confirm, there doesn’t appear to be any functionality specifically for the OP request, you have to do your own cleanup in your code so that between scripts runs you don’t have to worry about errant globals still lingering?