Posts: 720
Threads: 124
Joined: May 2019
I have a variable in the variables driver
Code:
Variables.EntertainmentRoomFamilyRoomMode
Normally, you would get the value with
Code:
$(Variables.EntertainmentRoomFamilyRoomMode)
Is there a way to dynamically build the variable name and then get its value? This obviously does not work
Code:
$(Variables.EntertainmentRoom%(LVar:CurrentRoom)Mode)
Is there a way?
Posts: 3,476
Threads: 157
Joined: Jun 2005
I think I do this somewhere in my templates but I cannot find where right now. If I remember correctly, the "Append" command works to build up a variable. I wish I could give you exact details, but maybe this will get you going in the right direction.
Brian - a long time user that rarely messes with the system now
Other systems used:
SageTV w/ cablecard tuner & multiple extenders for viewing
BlueIris and IP cameras for CCTV
Incredible PBX for home phone
Posts: 1,498
Threads: 142
Joined: May 2007
05-06-2020, 06:32 PM
(This post was last modified: 05-06-2020, 06:36 PM by kblagron.)
I do this on my system, which might be what you are looking for to build variables and then calling templates:
This button code sets a variable with the first part of the name "CTHD6.ZoneA", then sets the source number, then loads the FM Control Panel.
Code:
GlobalVars::SetVariable
P1=GVar:CTRoom
P2=Office
GlobalVars::SetVariable
P1=GVar:CTZone
P2=CTHD6.ZoneA
Devices::FieldWrite
P1=%(GVar:CTZone)SourceNum
P2=0
P3=True
GlobalVars::SetVariable
P1=GVar:CTSourceNum
P2=0
IntfViewer::InvokePopup
P1=./BL-AVControl
P2=
P3=-1, -1
P4=Center
Once the FM control panel is displayed, a button can be pressed to change the FM station, using the variables set in the previous template.
Code:
GlobalVars::SetVariable
P1=GVar:CTFMFreq
P2=89.30000
GlobalVars::SetVariable
P1=GVar:CTPower
P2=True
Devices::FieldWrite
P1=%(GVar:CTZone)Power
P2=True
P3=True
Devices::FieldWrite
P1=%(GVar:CTZone)FMFreq
P2=89.3
P3=True
I would assume you could do the same for field reads and variables.
Posts: 720
Threads: 124
Joined: May 2019
05-07-2020, 04:54 AM
(This post was last modified: 05-07-2020, 06:12 AM by gReatAutomation.)
Hey Thanks! I am actually trying to set a local variable dynamically based on what is in a field in the variables driver, but that I would like to, itself, call dynamically.
Here, I set a local variable. The
FamilyRoom part is what I want to be able to set dynamically.
Code:
LocalVars::SetVariable
P1=LVar:Mode
P2=$(Variables.EntertainmentRoomFamilyRoomMode)
Maybe I should dynamically build the
Variables.EntertainmentRoomFamilyRoomMode part first in a local variable.
Posts: 720
Threads: 124
Joined: May 2019
ugh, building it dynamically works, but I cannot call a field value based on the generated name.
Posts: 1,498
Threads: 142
Joined: May 2007
(05-07-2020, 06:50 AM)gReatAutomation Wrote: ugh, building it dynamically works, but I cannot call a field value based on the generated name.
When you say "call a field value" do you mean read it? Or something else?
Posts: 720
Threads: 124
Joined: May 2019
I need to do be able to do something like this. That is, set local variable
Mode. Note, the second parameter is setting the local variable to a field value. In this case, the value from the
EntertainmentRoomFamilyRoomMode field of the variables driver:
Code:
LocalVars::SetVariable
P1=LVar:Mode
P2=$(Variables.EntertainmentRoomFamilyRoomMode)
What I want to be able to do is not have to hard code the room name or use If/Else statements. Note the
%(LVar:Room) embedded. This does not work.
Code:
LocalVars::SetVariable
P1=LVar:Mode
P2=$(Variables.EntertainmentRoom%(LVar:Room)Mode)
Posts: 40,483
Threads: 491
Joined: Aug 2002
Don't try to nest tokens like that. It won't work. Use the ReadField and ReadField2 commands to read fields when you need to do that sort of thing. Then you can just build up the field name to pass by concatenating it:
Variables.EntertainmentRoom%(LVar:Room)Mode
That'll build up the name that you pass to read.
Dean Roddey
Explorans limites defectum
Posts: 720
Threads: 124
Joined: May 2019
Thanks. FieldRead2 can do it that way. Awesome.
Code:
Devices::FieldRead2
P1=Variables
P2=EntertainmentRoom%(LVar:CurrentRoom)Mode
P3=LVar:Mode
P4=True