|
SetTimedVariable Anonymous |
11 year
|
I would want to understand better this function, also with a practical example, because I believe that it is very useful for different purposes.
The "SetTimedVariable" a good explanation is not found, even in the guide online.
I have tried to copy this script in the form VBScript and to insert it in the pipeline, but I have not gotten some result.
In the documentation of VBScript_Plugin is written there: "...Note that usage of step and setting it to 1 and 3 which are dummy steps where nothing is done... " , then, which are the steps to insert ?
If an explanation could be had as soon as more deepened, it would be what pleasant.
Thanks.
|
|
|
David Chik from Japan [31 posts] |
11 year
|
Please try the following code:
select case GetVariable("state")
case 0:
write "0"
period = 2000
SetTimedVariable "state",2,period
SetVariable "state", 1
case 1:
write "1"
case 2:
write "2"
period = 2000
SetTimedVariable "state",4,period
SetVariable "state", 3
case 3:
write "3"
case 4:
write "4"
period = 2000
SetTimedVariable "state",6,period
SetVariable "state", 5
case 5:
write "5"
case 6:
write "6"
period = 2000
SetTimedVariable "state",8,period
SetVariable "state", 7
case 7:
write "7"
case 8:
write "8"
SetVariable "state", 0
end select
You should see 1,3,5,7,1,3,5,7... which means you can delete <write "0","2","4"...> but you can modify <write "1","3","5",...> to do the things you want (e.g. set motor values).
|
|
|
Steven Gentner from United States [1446 posts] |
11 year
|
We updated the SetTimedVariable documentation with a bit more description. It is essentially a way around using Sleep which should not be used as that shuts down all processing. Instead, think of using states where nothing happens to wait for something to complete. That's where the SetTimedVariable comes into play. Instead of
SetVariable("motor", 100)
Sleep(1000)
SetVariable("motor", 0)
use
SetVariable("motor", 100)
SetTimedVariable("motor", 0, 1000)
but you CANNOT call that same function again and again otherwise it will reset the timer. So when you do that, you need to jump into another state that does nothing. So the actual code is something like what follows. For example, to move the left motor for 1 second, then the right motor for 1 second and then stop for one second the code would look like:
select case GetVariable("state")
case 0:
SetVariable "left_motor", 100
SetTimedVariable "state",2,1000
SetVariable "state", 1
case 1:
' do nothing, this is the wait state, just let the motor values do its thing ... all vars are set
case 2:
SetVariable "left_motor", 0
SetVariable "right_motor", 100
SetTimedVariable "state",3,1000
SetVariable "state", 1
case 3:
SetVariable "left_motor", 0
SetVariable "right_motor", 0
SetTimedVariable "state",0,1000
SetVariable "state", 1
end select
|
|