0

Can anyone tell me if there is a way for me to use a variable within a lump of code, so that code can be looped to send messages to multiple objects?

For example, if I have 10 buttons and want each to send a variation of the same command 'sendCommandX', with X being the number of the button.

Right now I have 10 separate messages, and each button calls its own, like

on mouseUp
   sendCommand1
end

on mouseUp
   sendCommand2
end

Each of these 10 sendCommand# messages do the same thing, just with a different number in them.

It would be great if I could use a variable within the call, so I could have one reusable message. Like:

on mouseUp
   sendCommandX (X being the number of the button clicked)
end

and then the sendCommandX could use the same variable within, like

on sendCommandX
   echo "you clicked button X:
end
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
DrRocket
  • 215
  • 2
  • 14

1 Answers1

0

send the number as a parameter:

-- on Button 1
on mouseUp
  sendCommand 1
end

-- on Button 2
on mouseUp
  sendCommand 2
end

-- movie script!
on sendCommand which
  -- use 'which' here, e.g.
  put "You pressed button " & which
end

I guess your button scripts are cast member scripts?

This code would be better as a behavior, because then you'd only need one script. But it will work ok like this.

brennanyoung
  • 6,243
  • 3
  • 26
  • 44