i'm trying to read ini file, however it cannot seem read the ini file, even i put on or off only the first statement runs, any idea why?
heres in my skillmode.ini file
[skillmode]
toggle=off
heres my whole script
home::
Loop
{
test()
sleep, 1500
}
test() {
IniRead, value, skillmode.ini, skillmode, toggle
if(%value% = on) {
send, {f9}
msgbox, now its on!
return
}
else if(%value% = off) {
send, {f5}
msgbox, now its off!
return
}
else {
msgbox, nothing happened
return
}
}
simple script can't seem to read ini file
Re: simple script can't seem to read ini file
Code: Select all
If(value = on) ; set variable using 'expresion' style
Re: simple script can't seem to read ini file
i tried your suggestion but a messege boxBoBo wrote:Code: Select all
If(value = on) ; set variable using 'expresion' style
nothing happened appeared...
it seems it cannot read anything
test() {
IniRead, value, skillmode.ini, skillmode, toggle
If(value = on) {
send, {f9}
msgbox, now its on!
return
}
else If(value = off) {
send, {f5}
msgbox, now its off!
return
}
else {
msgbox, nothing happened
return
}
}
Re: simple script can't seem to read ini file
There should be a SPACE between the IF and first ( like so If (value = on)
-
- Posts: 302
- Joined: 05 Feb 2017, 00:03
Re: simple script can't seem to read ini file
Unless you really have a variable named on and are comparing to its contents, you need to put quotes around it.
Code: Select all
If (value = "on")
Re: simple script can't seem to read ini file
Using if (expression) statement, implies everything that is not enclosed in quotes to be the name of a variable, a function call, an integer etc. Either you can use such statements (and in this case you must put quotes around strings as stated by Nightwolf85 - unless it will be evaluated as a variable) or you can use traditional-if statement (but in this case the One True Brace (OTB) style is not allowed):
Also, make sure you specified:
on the top part of your script since your IniRead command doesn't use an absolute path.
Code: Select all
home::
Loop {
MsgBox % test() ; displays the value returned by the function
sleep, 1500
}
test() {
IniRead, value, skillmode.ini, skillmode, toggle
if value = on ; a traditional-if statement: no open-parenthesis after the word "if" and the One True Brace (OTB) style is not allowed
{
send, {f9}
return "now its " . value . "!" ; the dot is used to concatenate substrings when using expressions; in expressions everything that is not enclosed in quotes is supposed to be a variable
}
else if value = off
{
send, {f5}
return "now its " . value . "!"
} else return "nothing happened"
}
Code: Select all
SetWorkingDir %A_ScriptDir%