Notifications
Clear all

[Closed] Setting the value of a valueRef?

I have two rollouts. One rollout spawns from the other, and inside it I have a reference variable of type ValueRef to another variable in the main rollout.

    rollout MyRollout_Secondary "" width:120 height:30 (
        local ref
    ref = 5
    print (MyRollout_Main.bas_dt as string) --Should return 5 but does not :(
    ...

and in the main rollout:

on btn rightclick do (
    createDialog MyRollout_Secondary ;
    MyRollout_Secondary.ref = &bas_dt
)

The problem is, when I do

ref = 5

it simply replaces the reference variable with a non-reference variable = 5.

when I print ref as string, it returns

ref: RolloutLocal:bas_dt in rollout:MyRollout_Main

I can get the value of bas_dt by doing *ref but that also doesnt help me set the value which is what im trying to do.

if anyones interested, the reason im trying to do it like this instead of just directly referencing bas_dt in the secondary rollout like MyRollout_Main.bas_dt is because there are a few dozen buttons, and each of them spawns the secondary rollout when right clicked, but they each need to modify a different variable, so im trying to avoid having to create a unique rollout definition for each button.

2 Replies

You need to dereference the value before assigning to it (since you’re not passing it to a function that’d do the job for you):

*ref = 5

And yes, that should be all that’s needed, example code:

::MyRollout_Secondary

rollout MyRollout_Main ""
(
    local bas_dt = 0
    button btn
    on btn pressed do
    (
        createDialog MyRollout_Secondary
        MyRollout_Secondary.ref = &bas_dt
    )
)

rollout MyRollout_Secondary "" width:120 height:30
(
    local ref
    button btn
    
    on btn pressed do
    (
        x = *ref
        print x
        *ref = 5
        print (MyRollout_Main.bas_dt as string)
    )
)

createdialog MyRollout_Main

huh, it really do be that simple.

Maxscript works in mysterious ways… but at least it works
thanks!