Expression as argument... why not?
felixmoldovan
Posts: 197
Hello
Maybe obsolete, but still makes me ask WHY?
I have the sat-tv favourite channels stored as an bi dimensional array of integers:
Please somebody take off the blind spot in my brain, and explain why something like this will NOT work:
while this will always work. The only difference is storing the expresions as variable, and not using them as arguments for the PULSE
PS: The above is based on button events from buttons with the channel number equal with the preset I am selecting, and the +10 comes from the IR channel numbering (1=[dvDSTV,11], 2=[dvDSTV,12],etc)
Many thanks!
Maybe obsolete, but still makes me ask WHY?
I have the sat-tv favourite channels stored as an bi dimensional array of integers:
DEFINE_CONSTANT INTEGER DSTVCH [][3] = { {HundredsCH1, TensCH1, UnitsCH1}, ......, {HundredsCH10, TensCH10, UnitsCH10},...}
Please somebody take off the blind spot in my brain, and explain why something like this will NOT work:
PULSE [dvDSTV, DSTVCH[BUTTON.INPUT.CHANNEL][1]+10] WAIT 3 PULSE [dvDSTV, DSTVCH[BUTTON.INPUT.CHANNEL][2]+10] WAIT 6 PULSE [dvDSTV, DSTVCH[BUTTON.INPUT.CHANNEL][3]+10]and it will ONLY pulse correctly the Hundreds value (the others will be 0)
while this will always work. The only difference is storing the expresions as variable, and not using them as arguments for the PULSE
HUN = DSTVCH[BUTTON.INPUT.CHANNEL][1]+10 TEN = DSTVCH[BUTTON.INPUT.CHANNEL][2]+10 UNI = DSTVCH[BUTTON.INPUT.CHANNEL][3]+10 PULSE [dvDSTV, HUN] WAIT 3 PULSE [dvDSTV, TEN] WAIT 6 PULSE [dvDSTV, UNI]
PS: The above is based on button events from buttons with the channel number equal with the preset I am selecting, and the +10 comes from the IR channel numbering (1=[dvDSTV,11], 2=[dvDSTV,12],etc)
Many thanks!
0
Comments
BUTTON.INPUT.CHANNEL is a BUTTON_EVENT object value that is not available to the code after your WAIT. As you have the discovered, the value will be zero when trying to define the element of your array.
This how the run time will interpret those lines.
So,
now replace all the Button.Input,channels in your other statments with Button_pushed and it'll work just fine.
There is nothing to argue with here, since the facts are happening exactly how you describe them, it just seems that the AMX documentation has misled me when saying, under "Button Events" that
"The BUTTON object is available to the button event handler as a local variable",
which, in my understanding, would have had to be kept stored for the whole life span of that BUTTON_EVENT, and not reset after once used...
[INNER MONOLOGUE]
And, just to confuse me more, even in the example above I am referencing three times to BUTTON.INPUT.CHANNEL when storing it's value in the HUN, TEN, UNI variables. Right... not using any WAIT this time.
Does it have to do something with, maybe, the fact that during the WAIT time another button event might have occurred? (The release...) But even then, we are talking about the same button, just not stored because there is no RELEASE: statement in my button event?
[/INNER MONOLOGUE]
felixmoldovan wrote: No. An event object will always have a value of zero outside the event because it doesn't exist outside the event.
I guess they could make it so it gives you a complier warning when used in a wait since it is then technically outside the event like a stack var.
This goes right on top of my "Netlinx for dummies" list!
Thanks. If, axiomatically, I refer to the above, then suddenly the TV is showing the right bloody channel :-)
Global variables that track events reset each pass of mainline, as I understand it. If the code runs right away, it will remain good until the next event overrides it, but the wait pushes it past that reset point.
I have a question for you, why not uses the XCH command? Seems to be alot of work around something a command has been created to do automatically...
// PULSES THE CORRECT CHANNELS FOR CHANNEL 123
SEND_COMMAND dvTV,'XCH 123'
Nevertheless, I abandoned that as soon as I realized there will be NO WAY to keep track of the actual channel the decoder is on, because of many factors, including the concurrent use of the supplied remote...
And yes, even with integers, it could have worked very well and easier your way, even with leading 0...