Fixed Random Variable

Discuss RoboTask here
Post Reply
george
Posts: 25
Joined: Sun Mar 25, 2018 3:02 pm

Fixed Random Variable

Post by george »

Hi, I've been trying to do something with no success.

I have at the start of a task a {NUMBER} variable set with {RandomValue(23)}, what that does is everytime I use {NUMBER} in next steps of the task the integer changes to a new random number.

Is there a way I can run only once {RandomValue(23)} and assign it to a variable that I'll be using several times later in the same task, with the same random number assigned at the start? :roll:

Thanks
Oleg
Site Admin
Posts: 3010
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Fixed Random Variable

Post by Oleg »

Pay attention to this option (look at screenshot below)
ExpandNow.png
ExpandNow.png (12.12 KiB) Viewed 7061 times
If it is ON then the action calculates the value and save the result into variable
If it is OFF then the action saves specified string as-it-is. So you get different values in different steps, because RoboTask calculates the value every time when you use this variable.

Also look at my two examples. These examples demonstrates this option.
1-st example. You get new value every time

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|953684383
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task185"
Hide=INTEGER|0
ID=INTEGER|-1830014808
LogOnAsUser=INTEGER|1
Name=STRING|"random (NOT fixed)"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""VALUE"" with value ""{RandomValue(23)}"""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
varname=STRING|"VALUE"
varvalue=STRING|"{RandomValue(23)}"

[Actions\Action2]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""{value}"""
Params=FOLDER

[Actions\Action2\Params]
icon=STRING|"1"
msg0=STRING|"{value}"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action3]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""{value}"""
Params=FOLDER

[Actions\Action3\Params]
icon=STRING|"1"
msg0=STRING|"{value}"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action4]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""{value}"""
Params=FOLDER

[Actions\Action4\Params]
icon=STRING|"1"
msg0=STRING|"{value}"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"
2-nd example: you get the same value in different steps

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|953684383
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task186"
Hide=INTEGER|0
ID=INTEGER|679974520
LogOnAsUser=INTEGER|1
Name=STRING|"random (fixed)"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""VALUE"" with value ""{RandomValue(23)}"""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"1"
varname=STRING|"VALUE"
varvalue=STRING|"{RandomValue(23)}"

[Actions\Action2]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""{value}"""
Params=FOLDER

[Actions\Action2\Params]
icon=STRING|"1"
msg0=STRING|"{value}"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action3]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""{value}"""
Params=FOLDER

[Actions\Action3\Params]
icon=STRING|"1"
msg0=STRING|"{value}"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action4]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""{value}"""
Params=FOLDER

[Actions\Action4\Params]
icon=STRING|"1"
msg0=STRING|"{value}"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"
Oleg Yershov
george
Posts: 25
Joined: Sun Mar 25, 2018 3:02 pm

Re: Fixed Random Variable

Post by george »

Works perfect, thanks!
Mokrun
Posts: 2
Joined: Tue Oct 02, 2018 12:19 pm

Re: Fixed Random Variable

Post by Mokrun »

Thanks this a useful
Post Reply