I have a dynamic panel with 3 panel states let’s say each state has text in it A, B & C - controlled by another interaction. When clicking a button I want to set a variable (let’s call it stateVar) to be the text from the respective panel state. At the moment setting stateVar to ‘state of panel’ results in the panel state name being retrieved e.g. ‘State 2’ and not ‘B’ as needed. any way I can get the text from a panel state?
The dynamic panel widget itself does not have a text value, so you must have a widget within each state that contains your text values (‘A’, ‘B’, ‘C’). You’ll need to specify one of these widgets in your Set Text action. I recommend naming these widgets uniquely so they are easier to find.
Now, if you only need to refer to something simple and static, for example, the text for the first state will always be “A” and won’t be dynamically changed, then you can use the name of the state–which is what you are currently doing. As you noticed, when you set a variable to “state of panel” that refers to the name of a dynamic panel’s state–by default, the name is “State 1”. You can change this to “A” by editing the name in the OUTLINE pane or INTERACTIONS pane.
Thanks for such a clear and informative answer. I’ll give it a try
I think I am encountering the same problem even though I now have named widgets in each of my states - I can’t see away to set my variable to whichever one is dynamically active. So if State 2 is active and in it is a widget called ‘B’ - how do I set stateVar to be ‘B’? The active state could be either 1, 2 or 3.
Ah. I guess I glossed over some details you may not be aware of. Here is a quick demo file:
dynamic panel changes var.rp (77.8 KB)
There are two pages, each showing one of the methods I described above.
Page 1 has a dynamic panel with three states, and each state has a widget containing text, either ‘A’, ‘B’ or ‘C’. If you select the dynamic panel and look in the INTERACTIONS pane, you can see the PANEL STATE CHANGED event is used.
- It has three conditional cases to handle each possible state change.
- Each case sets the value of (the default) global variable, OnLoadVariable, referring to the widget in that state.
- To make it easier to see the value of OnLoadVariable, I also set the text of a widget named “var placeholder” (Or, you can open the Console panel of the Preview in the browser to monitor the current values of global variables.)
- To demonstrate all this, I inlcuded a button that simply changes the state of the dynamic panel to “Next, wrap”
Page 2 has a dynamic panel without any widgets for A, B, C. Rather, I named the states to ‘A’, ‘B’ and ‘C’.
- The PANEL STATE CHANGED event now sets OnLoadVariable to “state of This” --meaning the state name (as you discovered it does.)
I hope this makes sense.
Ahhh - of course! Setting the global variable from the ‘panel state change’ rather than from another button…GENIOUS.
Many thanks again for your well-thought-through and considerate answer. And example file.