Sign in to follow this  
Followers 0
fRequEnCy

Noob needs help with IniRead

6 posts in this topic

#1 ·  Posted (edited)

I am running a program from commandline:

Example: program.exe gamename

kpress = number of key presses needed to reach correct game.

settings.ini contains:

[game1]

kpress = 0

[game2]

kpress = 1 and so on........

CODE
$selectgame = IniRead ("settings.ini", ??, "kpress", "Not Found")

Code works great when I fill in ?? with game name.

What I would like help on is how to make ?? read the correct game from the commandline. Any help would be great! Thanks in advance.

So if I run from commandline then it will select the right game from the program based of the kpress.

Edited by fRequEnCy

Share this post


Link to post
Share on other sites



$CmdLine is an array that holds commandline parameters to your program. It's a built in, you don't have to do anything to set it up. Look in the help for "Command Line Parameters"

So,

$selectgame = IniRead ("settings.ini", $CmdLine[1], "kpress", "Not Found")

Share this post


Link to post
Share on other sites

$CmdLine is an array that holds commandline parameters to your program. It's a built in, you don't have to do anything to set it up. Look in the help for "Command Line Parameters"

So,

$selectgame = IniRead ("settings.ini", $CmdLine[1], "kpress", "Not Found")

Awesome! Thanks soooo much covaks! Was stuck looking for a way to set a variable to do what I needed. Works great and so simple. LOL. Thanks again!

Share this post


Link to post
Share on other sites

Works great but have one question..... Am able to run fine in dos but when run from ai3 i get an error. Is that normal?

Error:

Array variable has incorrect number of subscripts or subscript dimension range exceeded.

Also I get this error if run from commandline with no parameter.

Share this post


Link to post
Share on other sites

Fixed with:

If $CmdLine[0] = 0 Then Exit

If not correct please let me know.

Share this post


Link to post
Share on other sites

Yes, that's right. If you use Scite you can enter in Parameters by hitting Shift+F8. However, if you just run the .au3 file, or run the program by double clicking, it will error unless you write some kind of error handling for when no command line args are passed. Usually I output something back to the user so they know what the problem is though

If $CmdLine[0] = 0 Then
    Run(@ComSpec & " /c echo Error: Parameters are not optional & echo. & echo Usage: foo.exe param1 param2.. & echo. & pause")
    Exit 2
ElseIf $CmdLine[1] <> "-r" AND $CmdLine[1] <> "-w" Then
    Run(@ComSpec & " /c echo Error: First parameter must be either Read (-r) or Write (-w) & echo. & pause")
    Exit 3
EndIf

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0