2012-10-02 32 views
0

我不是一個AutoHotkey的大師,而我在與遞減可變麻煩,如果是大於0每秒一次:的AutoHotkey - 遞減變量每秒一次

Loop 
{ 
If spaceFreq > 0 
    spaceFreq-- 
If returnFreq > 0 
    returnFreq-- 
Sleep, 1000 
} 

這有什麼問題腳本?變量沒有被減少。

回答

0
to decrement a value and store the result back in the same variable directly, 
you must do 
ex: Var := --x instead of Var := x-- 
because --x decrements X immediately and then assigns its value to Var 
x-- increments X only after assigning the current value of X to Var consequently, 
not modifying the original variable, if no variable is specified. 

瞭解更多關於here ...遞減我 建議使用SetTimer,而不是循環和睡眠..

例如:

#Persistent 
SetTimer, decrementlabel, 1000 ;1000 ms = 1 second 
return 

decrementlabel: 
If spaceFreq > 0 
    --spaceFreq 
If returnFreq > 0 
    --returnFreq 
return