Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dynamically Build Call to Variable?
#1
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  Wink

Code:
$(Variables.EntertainmentRoom%(LVar:CurrentRoom)Mode)

Is there a way?
Reply
#2
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
Reply
#3
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.
Reply
#4
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.
Reply
#5
ugh, building it dynamically works, but I cannot call a field value based on the generated name.
Reply
#6
(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?
Reply
#7
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)
Reply
#8
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
Reply
#9
Thanks. FieldRead2 can do it that way. Awesome.

Code:
Devices::FieldRead2
    P1=Variables
    P2=EntertainmentRoom%(LVar:CurrentRoom)Mode
    P3=LVar:Mode
    P4=True
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable Action "Find" command or alternate Shaky 3 778 11-02-2021, 08:19 PM
Last Post: Shaky
  Action wait and exit if variable changes simplextech 8 3,253 02-01-2020, 12:35 PM
Last Post: simplextech
  Set value via HTTP Call simplextech 2 1,412 01-07-2020, 04:39 PM
Last Post: simplextech
  Time formatting RunTime Time Variable? gReatAutomation 5 2,425 08-14-2019, 05:23 AM
Last Post: gReatAutomation
  GVar... Variable GVar... Already Exists gReatAutomation 3 1,647 08-13-2019, 01:15 PM
Last Post: Dean Roddey
  Creating a Variable Double_J 13 5,047 06-22-2019, 03:40 AM
Last Post: gReatAutomation
  new build charles 10 4,158 05-23-2019, 09:38 PM
Last Post: znelbok
  Variable Error in Scheduled Task znelbok 3 2,005 03-22-2019, 09:30 AM
Last Post: Dean Roddey
  Question on Formatting of Variable Text kblagron 2 3,103 09-07-2018, 08:52 PM
Last Post: kblagron
  How would I manually collect digits to enter into a variable ghurty 1 1,610 05-24-2018, 08:51 PM
Last Post: Dean Roddey

Forum Jump:


Users browsing this thread: 1 Guest(s)