When scripting a multistate button in perspective, how do I know which button has been pressed

Hi Everyone

I am trying to create a "mater script" for buttons. Basically I would have a project library script that depending on the calling component, write different commands to Modbus.

Here I am having issue with the multistate button. It is a button that turn the plant to OFF/MANUAL/AUTO/ON state. So far I find out that you can configure values for different state in it's properties, and the controlValue will change to that corresponding value upon clicking. However I am wondering if there are any other values I can rely on, because the function that is called will be relying on magic numbers to work out what has been clicked.

Any help is appreciated!

You are expected to use the "magic numbers" that correspond to your PLC's requirements.

Could you just pass those “magic numbers” in as an expected input to your function?

The multistate has properties where you set the button values. You could easily pass those properties in to determine which button was clicked.

It sounds like you are trying to “objectify” for the sake of objectivity by creating this master script. Keep it simple and tie the buttons to the tag it should control.