simple script can't seem to read ini file

Get help with using AutoHotkey and its commands and hotkeys
ravena1
Posts: 14
Joined: 06 Sep 2017, 15:13

simple script can't seem to read ini file

25 Nov 2017, 01:43

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
}
}
BoBo
Posts: 3869
Joined: 13 May 2014, 17:15

Re: simple script can't seem to read ini file

25 Nov 2017, 02:23

Code: Select all

If(value = on) ; set variable using 'expresion' style
ravena1
Posts: 14
Joined: 06 Sep 2017, 15:13

Re: simple script can't seem to read ini file

25 Nov 2017, 04:23

BoBo wrote:

Code: Select all

If(value = on) ; set variable using 'expresion' style
i tried your suggestion but a messege box
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
}
}
Guest

Re: simple script can't seem to read ini file

25 Nov 2017, 04:53

There should be a SPACE between the IF and first ( like so If (value = on) :?:
Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: simple script can't seem to read ini file

25 Nov 2017, 07:37

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")
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
GitHub: AAhkUser
Location: France

Re: simple script can't seem to read ini file

25 Nov 2017, 08:11

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):

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"
		
}
Also, make sure you specified:

Code: Select all

SetWorkingDir %A_ScriptDir%
on the top part of your script since your IniRead command doesn't use an absolute path.
my scripts

Return to “Ask For Help”

Who is online

Users browsing this forum: artur1884, gwarble, linearsoulchild, mikeyww, TAC109, WeedTrek and 29 guests