gignu
gignu

Reputation: 2485

Possible to save commands in variables?

My idea was to a command like "Sleep, 2000" in a variable or even several commands. In this example you would type in the hotstring, then the program would wait 2 seconds and then the message box would pop up and tell you that you've slept for 2 seconds. However, I'm getting an error message for the line with "SleepVar1": "This line doesn't contain a recognized action"

SleepVar1 = Sleep, 2000

:*:svar::
SleepVar1 
msgbox, You slept 2 seconds
return

There must be a way to achieve this, right? Maybe not with variable but something else.

Upvotes: 1

Views: 77

Answers (1)

Relax
Relax

Reputation: 10543

As the names suggest:

  • Commands are orders, tasks given to the OS.
  • A variable is a placeholder for a value. The value can change, nevertheless a variable can only hold one value at a time.

To return a given value of a variable within commands, you need to enclose the variable in percent signs

SleepVar1 = 2000

:*:svar1::
    Sleep, %SleepVar1% 
    msgbox, You slept 2 seconds
return

or a function:

; :X*:svar2::SleepVar(3000)

; or

:*:svar2::
    SleepVar(3000)
return

SleepVar(value){
    Sleep, %value%
    msgbox, You slept %value% miliseconds
}

Upvotes: 2

Related Questions