Waits & Variables
jabramson
Posts: 106
What is the best way to handle a variable in a wait? For Example
the send_string i will be grabbing the current value of i which isn't necessarily somewhere inbetween 1 and 100.
I've gotten around this by creating a queue that the for loop dumps in to and then is processed elsewhere, but is there a better way?
FOR (i=1; i<=100; i++) { wait i send_string device,"itoa(i)" }
the send_string i will be grabbing the current value of i which isn't necessarily somewhere inbetween 1 and 100.
I've gotten around this by creating a queue that the for loop dumps in to and then is processed elsewhere, but is there a better way?
0
Comments
I don't think that the code that you have written will do what you want. It will only create one wait and the value of i when the wait expires in .1 second will, in all probability, be 101.
My understanding is that you can't create multiple waits with one line of code. If you have a function with a wait in it and call that function multiple times real, real fast, you only get one wait. This is because, as I understand it, that Netlinx considers all waits created with a single line of code to be the same wait and you can only have a single wait running one time. This is easier to understand if you have a named wait and the rule is that you can only have one of a named wait at a time. Seems like however it is that Netlinx identifies un-named waits, it assigns the same identifier to it each time.
So, the answer to the question you should be asking is, "use a timeline."
If you put variables in a wait you have to keep in mind they could change before the execution of the wait. Hence no stack_vars (because those won't exist after the block they are defined in exits) but local_vars and globally defined variables are okay. There are various ways to mitigate this restriction but it depends on your application.
You could do this with a timeline a lot more effectively. It will do what you want.