Monday, July 30, 2007

[oopic] Re: Silly question (first of many)

--- In oopic@yahoogroups.com, "jueysmum" <c9403328@...> wrote:
>
> Hi
> In the following code, if I move the if construct outside of the
> event handling code, the robot will not stop. If I leave it in it
> will. I've done a few further experiments with the code for the
> value of counter - some will work outside the event handler, some
> won't why is this? Counter is a global variable so why the
> difference?
>
> Dim LeftServo as New oServoX
> Dim RightServo as New oServoX
>
>
> Dim CountAdd as New oEvent
> Dim Wire as New oWire
> Dim RightWire as New oWire
> Dim ScreamWire as New oWire
>
> Dim Scream as New oFreq
>
> Dim Counter as New oByte
>
> Sub Main()
>
> LeftServo.IOLine = 29
> RightServo.IOLine = 30
> RightServo.InvertOut = cvTrue
>
> LeftServo.Value = 127
> RightServo.Value = 127
>
> Counter.Value = 0
>
>
> LeftServo.Operate = cvTrue
> RightServo.Operate = cvTrue
> Wire.Input.Link(OOpic.hz1)
> Wire.Output.Link(CountAdd.operate)
> Wire.Operate = cvtrue
> Scream.Value = 61473
> End Sub
>
> sub CountAdd_CODE()
> Counter.inc
> Scream.operate = cvtrue
> Oopic.delay = 10
> Scream.operate = cvfalse
> if Counter.value >5 then
> RightServo.Operate= cvFalse
> LeftServo.Operate = cvFalse
> end if
> end sub
>
> Jueysmum
>


You should be able to move the 'if Counter.value ...' outside of the
event code but you do have to put it in a loop.

Do

...
if Counter.value ...
...

Loop

There is no implied loop when you get to the end of sub Main() -
processing of the script is finished. Virtual circuits and event code
continues indefinitely.

You really don't want script code in a loop if you can avoid it.
Executing code is not particularly fast on the OOPic.

Richard



Yahoo! Groups Links

<*> To visit your group on the web, go to:

http://groups.yahoo.com/group/oopic/

<*> Your email settings:
Individual Email | Traditional

<*> To change settings online go to:

http://groups.yahoo.com/group/oopic/join

(Yahoo! ID required)

<*> To change settings via email:
mailto:oopic-digest@yahoogroups.com
mailto:oopic-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
oopic-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:

http://docs.yahoo.com/info/terms/

No comments:

Post a Comment