Jump to content

Noob needs help with IniRead


Recommended Posts

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
Link to comment
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")
Link to comment
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!

Link to comment
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.

Link to comment
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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...