Button Events using get_last
bb3177
Posts: 2
I have been using the get_last(array) for getting the last button/channel pressed from an array of touchpanels. I currently use a single array called channels and pass that to all of the modules I made. I noticed that there could be a situation in which there are two panels being used at the same time and could interfere with each others operation depending on how the events operate. Is it a common practice to use a different array of integers containing the channels for each array of TPs?
0
Comments
Well, a lot depends upon your code.
in the strictest sense, a set of events don't happen at the same time. One will always occur before another. they might be incredibly close together timewise, but the don't happen (computer tick-wise) simultaneously.
Having said that, you do need to take care that your button events reference things that A) do not allow the second event to do anything until you're darned sure the first is done or make sure your functions being called upon don't use any system-wide variables that the values can change during the operation of the event.
You could, in theory, create a queue for all your button pushes and let that handle the rate at which your program deals with button events.
There are a variety of ways to handle the problem you describe.
Having said that, I do have some of my older programs out there chocked full of system wide variables on button events that have never collided. I wrote them way back when dinosaurs roamed the Earth and I didn't know better. In general, if you BEs use Stack_Vars and reference functions in the end, you'll probably be okay. If you're experiencing collisions, you'll have to write a queue for them to keep the cats herded properly.
I queue my stuff myself when I've got a lot of panels.
Usually there's a work around but it is conceivably possibly that you may need a button event handler fo each UI. You wouldn't need seperate arrays though just a seperate button event for each UI.
Ditto for me too.
Talking about waits, does the wait work as a "mimic" or "fake" to threading, similar to a costate/wait/waitfor/yield? Where the processor passes the program control over to another section of code and waits to execute the remaining section until some condition is met. How is threading or multitasking done in netlinx?
This might be an interesting read: http://www.amxforums.com/showthread.php?1473-Release-Time
Keep in mind, get_last has been changed recently so it could be used in a HOLD event. I guess what you *could* do is lock out the ability of firing the event all together if it's too close.
Example theory:
The problem discussed earlier with changing value occurs when you have waits in your event code or in any code triggered by your event code. The waits are seperate events and are processed when the wait time completes and the master may have processed several other pushes depending on how long the wait time is and how many users are using at the same time. So if a button is pushed on a TP and that event runs and comes across a wait which uses a local or global var of some value and this value is assigned outside of the waits code block it will change but since the wait is pending that code won't work for the second button push but it will possibly change the value of the vars used in the wait's related code that's pending for the first button push.
Hope that helps but it is a little confusing.
One way around this as E was eluding to is to create your own queue for stacking events (pushes in this case) and process them in a timeline that repeats at a rate longer than your longest wait or some flag. Fortunately most button events don't need waits since they usually generate strings to devices. Those strings can be put in queues to control their delivery timing whether you just seperate send strings by a fixed time period or wait for a ack from the deivce before sending.