|
ANY-maze Help > The ANY-maze reference > The Protocol page > The elements of a protocol > Testing > Procedures > Writing a procedure using the procedure editor > Errors and warnings while writing a procedure > Error: Cannot use an event in an 'If' statement without first waiting for that event to occur Error: Cannot use an event in an 'If' statement without first waiting for that event to occur
DescriptionIf you want a procedure to wait for an event to happen, this must be done using a Wait until statement, and not an If statement. More informationIt's a common mistake to try and write a procedure like the following:
Figure 1. This procedure is not valid, because it uses the event in an If statement instead of a Wait until statement.
To see why the above procedure wouldn't work, let's consider how a procedure actually runs. Procedures run through their statements in order, starting when the test starts, and only stopping at the end of the procedure or when it reaches a Wait until statement which means it's got to hang around and wait for something specific to happen. This means that each statement is only processed at a single point in time, then the procedure moves on. Looking at the procedure in figure 1, you can see that as soon as the test starts, the procedure gets to the If statement. It runs this If statement by evaluating its condition to see if it is true. The Animal enters Island zone event isn't occurring at this exact time (even if the animal starts the test already in the island zone, the procedure is currently processing the 'test start', and there hasn't yet been an event to say that the animal has entered the zone), so the condition is not true. The procedure therefore doesn't execute the statements within that condition, and drops out of the If statement. There are no more statements in the procedure, so the procedure finishes. Obviously, now that the procedure has finished, it can no longer detect a zone entry to the island zone when it happens.
The solution to this is to rewrite the procedure using a Wait until statement:
Figure 2. This procedure will wait until the zone entry event happens, before ending the test.
Again, if we consider how this procedure actually runs, we can see how this will function correctly where the procedure in figure 1 would not. At the start of the test, the procedure gets to the Wait until statement. The condition for the Wait until statement is not true (as we ascertained above), so the procedure 'pauses' and lets other procedures have a chance to run. As the test progresses, the tracking continually reports animal movements, and whenever this happens, a 'test event' is generated for the new position. Each time this happens, the procedure gets the chance to run again. Each time it starts at its current statement - the Wait until statement - and evaluates it to see if the event is what the procedure is waiting for. A simple animal movement is not what the procedure is waiting for, so again it pauses at the same point, and lets other procedures have a turn. This happens repeatedly throughout the test, whenever something new happens - the animal moves, freezes, the state of an I/O input changes, etc. At some point, the animal's movement may mean that it's now in the Island zone. When this happens, ANY-maze generates a 'zone entry' event which is passed to all procedures. Once again, this procedure is given its chance to run; it looks at the condition of its current statement, the Wait until statement, to see if the event is what it's waiting for. It is the right event now, so the condition is true; the procedure moves on and executes the next statement, which is to end the test. The ending of the test also ends the procedure.
If a procedure is written which uses an event in an If statement without first using it in a Wait until statement, this error will be generated in the list of errors and warnings at the bottom of the procedure editor when you check the procedure for errors or exit the procedure editor. See also:
© Copyright 2003-2026 Stoelting Co. All rights reserved ANY-maze help topic T0503 |