PDA

View Full Version : Doing Math on a Button



dsmes
January 23rd, 2007, 08:02 PM
You can display text and a NR variable in a button's name like:
Button text and {NR.variable.name}

And you can display the Loop Index token in a button like:
Button text and <LoopIndex>

What I'd like to do is have the button compile the sum of the two like
result = tonumber(NetRemote.GetVariable('NR.variable.name)) + <LoopIndex>and display the result along with text in a button like:
Button text and [result]

Is this possible? If so, what is the syntax?

Rob H
January 24th, 2007, 02:32 AM
You may be able to do this using a Lua state for the button although I haven't tested this

Since the thing you want to be monitoring is ''NR.variable.name" the code would have to look something like this


local value = NetRemote.GetVariable('NR.variable.name')
if tonumber(value) then
value = value + <LoopIndex>
NetRemote.SetVariable('NR.othervariable.name', value)
end
return true -- if this is a hidden alternate state then use return false instead


Then your button would be called {NR.othervariable.name}

dsmes
January 24th, 2007, 06:42 AM
Rob,
As always, thanks a lot! It worked... but only after converting to the NRD1.1 format.

I did notice an unintended and unwelcome consequence of doing this. Usually as you adjust a slider, the NR variable associated with it updates in real time. But once you add Lua code to a state as I did here, the slider will only update when you release the slider button. To be clear, the slider button will move as you slide it, but the slider variable will no longer update in real time. And yes, the "Send on release only" box in the Slider Thumb Component option is un-checked.

Moreover, ANY slider on the same page will no longer update in real time. Even sliders whose NR variables are NOT referenced in the LUA code will not update in real time. Sliders on other pages work as expected, including a copy of the slider referenced in the Lua script.

Rob H
January 24th, 2007, 07:05 AM
Edit the slider and make sure that 'Send on release' isn't checked - the conversion to 1.1 format may have defaulted it to that.

dsmes
January 24th, 2007, 09:28 AM
Edit the slider and make sure that 'Send on release' isn't checked - the conversion to 1.1 format may have defaulted it to that.Been there, did that; it is NOT checked. I even checked and un-checked the box to be sure.

Ben S
January 26th, 2007, 06:27 PM
Can you have lua script create the variables before hand? Then you can use that in the button?

dsmes
January 27th, 2007, 05:34 PM
Can you have lua script create the variables before hand? Then you can use that in the button?That's what I ended up doing. I was trying to avoid that at the time... it seemed overkill and I was hoping for a simpler way. But now I'm fine with it.

Ben S
January 29th, 2007, 04:48 PM
Sounds good. :)