View Full Version : using variables with the -command flag

06 June 2007, 06:08 PM
When I specify a command via –command for a button or slider or other UI element, there doesn’t seem to be a good way to use a variable as part of that command. The script I'm writing has a lot of procedurally created buttons, and I want to have them call a particular proc when they are pushed and pass a number to that proc. Namely, the number of that particular button. For example:

button -c "myProc($numButtons)";Where $numButtons is the number of buttons that exist so far. This doesn't work since when the button is pressed it is literally executing "myProc($numButtons)" instead of "myProc(4)" or whatever the number was, so it says $numButtons is undeclared. Using a global variable doesn't work either, since it will always pass myProc the CURRENT value of $numButtons and not whatever the value was when that particular button was created.

Is there any way around this?

06 June 2007, 12:44 AM
try this:

button -c ("myProc(" + $numButtons + ")");

06 June 2007, 03:54 PM
That's exactly what I've been looking for. Many thanks!

CGTalk Moderation
06 June 2007, 03:54 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.