[Closed] why this code remembers previous value?
Hi,
This is the piece of code:
try(destroyDialog test)catch()
rollout test "test" (
on test open do (
global val = random 0 9999
format "this is your value: %
" val -- this
)
spinner _val "value:" type:#integer range:[0,9999,val] -- and this should be the same
)createDialog test
Issue is that the value val on every run is different in each of the lines of code. The printed value is the correct one, but the one in the spinner is a value from the previous run.
This does not make sense since I call a global random on opening the rollout
Because by the time the “open” event fires up, the spinner control was already built.
If you set “val=undefined” and run your script again, you’ll get an error.
Try either of these:
(
try(destroyDialog test)catch()
rollout test "test"
(
global val = random 0 9999
spinner _val "value:" type:#integer range:[0,9999,val]
on test open do format "Current Value: %
" val
)
createDialog test
)
(
try(destroyDialog test)catch()
rollout test "test"
(
global val = random 0 9999
spinner _val "value:" type:#integer range:[0,9999,val]
on test open do
(
val = random 0 9999
_val.value = val
format "Current Value: %
" val
)
)
createDialog test
)
EDIT: Fixing forum formating…
because maxscript first parses the code and creates the rollout and spinner ( using the current value at this time). After that it runs the code inside the rollout, assigns a new random value, and prints the new value via your “format …” call . But the spinner already exists at this time, having still the old value assigned
Edit: PolyTools3D was quicker