Use GET_LAST outside button events?
fogled@mizzou
h4x354x0r
I'm using arrays of button numbers in BUTTON_EVENTs with GET_LAST(Button_Array) to pass indexes off to calls and functions. But there are a couple of places where I'd really like to use that same functionality inside a call or a function (i.e. I end up with the button number in a call but I need an index for it).
Am I stuck using a FOR loop to get this info when I can't rely on GET_LAST, or is there another function like "GET_INDEX" that I can't figure out? Can I do something inside a call to access the array like BUTTON_EVENT does, so that I can immediately use GET_LAST to retrieve the index?
Thanks,
Am I stuck using a FOR loop to get this info when I can't rely on GET_LAST, or is there another function like "GET_INDEX" that I can't figure out? Can I do something inside a call to access the array like BUTTON_EVENT does, so that I can immediately use GET_LAST to retrieve the index?
Thanks,
Comments
-
While I try to avoid using button array indexes, because it's a trap for the next person to look at your code, here are two solutions.
First, pass the index as well as the button number to your function.
Second, put the index value into a global variable inside the event code. -
From the NetLinx Keyword help:
GET_LAST works with BUTTON_EVENTS and CHANNEL_EVENTS, but not with LEVEL_EVENTS
GET_LAST() can not be used outside of Events -
It will retain the last channel event that applies ... but you cannot trust it to be accurate outside of the button event handler. Once the running code passes outside of the handler, anything can change it that overlaps the device and/or channel you are using it on.
My solution is to simply create a variable, and use GET_LAST within the event to assign a value to that variable. You can then pass this variable to any outside function you desire; since it's your own variable, you have full control over what can modify it and insure it's OK when you are actually using it. -
Marc Scheibein wrote:From the NetLinx Keyword help:
GET_LAST works with BUTTON_EVENTS and CHANNEL_EVENTS, but not with LEVEL_EVENTS
GET_LAST() can not be used outside of Events
altough my experience is contradictory to this.LEVEL_EVENT[dvTP,nLevels] { STACK_VAR INTEGER nColor nColor=GET_LAST(nLevels) nLevelValue[nColor]=LEVEL.VALUE }
works perfectly and I have been using for more than a year.
but: make sure to use Levels 1-10 or somethin on each port, and if not try SET_VIRTUAL_LEVEL_COUNT to something -
REBUILD_EVENT wrote:LEVEL_EVENT[dvTP,nLevels]...works perfectly and I have been using for more than a year.
Very interesting! You're either lucky or I'll be able to replicate. -
Get_last just retreives an internal variable stored by the array referenced, kind of like the length. The variable gets set any time an event involving that array occurs so you have to be careful about what's accessing the arrays. I think, since you can't gurantee what get_last will return outside an event, that they tell you to not use it outside of events.
I ran a test with this function:define_function getlasttest() { send_string 0,"'TP:',itoa(get_last(dvTP))" }
And it worked when called from a button event. -
I think if you are using a Get_Last in a function that is only called by a Button or Channel Event then the function is in itself a continuation of the event and using a Get_Last there should not be a problem. But for the sake of proper coding ettiquatte it would be be a better technique to just to pass it the value.
If that doesn't do it for you then just set a global var in the event and then call it where ever it's needed as previuously suggested.
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums
