[PLUGIN]Command Line

This forum is currently in read-only mode.
0 favourites
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • Command Line Plugin - v0.92

    Download Now(no example) - 101KB

    Description:

    This plugin allows you to access and interpret all command line arguments passed to your program upon loading. This is useful for passing instructions or file paths to your program before startup.

    Conditions/Actions/Expressions/Edittime Parameters:

    Conditions:

    For each argument - Loops through each argument passed to your program. To be used in conjunction with the conditions specified under the "For each" category.

    Actions:

    Execute file - Allows you to execute an external program and supply it a set of command line arguments. Arguments are separated using Microsoft Windows standards.

    Expressions:

    Argument count - Returns the amount of arguments passed to your program.

    Get argument - Returns the entire argument at the index given in parenthesis(1-indexed).

    Get argument name - Returns the name of the argument at the index given in parenthesis(1-indexed). In the argument "value=5", "value" is the name.

    Get argument value - Returns the value of the argument at the index given in parenthesis(1-indexed). In the argument "value=5", "5" is the value.

    Get program path - Returns the path to the currently running program, file name and all. Windows usually passes this as the first argument, but it was relegated to an expression to avoid confusion.

    Current argument - Returns the entire currently iterated argument from the "For each argument" condition.

    Current argument index - Returns the index of the currently iterated argument from the "For each argument" condition.

    Current argument name - Returns the name of the currently iterated argument from the "For each argument" condition. In the argument "value=5", "value" is the name.

    Current argument value - Returns the value of the currently iterated argument from the "For each argument" condition. In the argument "value=5", "5" is the value.

    Edittime Parameters:

    Start arguments - A list of arguments that can be passed to your program internally at the start of the application. This allows the easy testing of command line features without exporting the program as an EXE. Arguments are separated using Microsoft Windows standards.

    Use start arguments - Determines whether the arguments specified in the "Start arguments" box will be passed to the program at the start of the application. It is recommended that this remain unchecked when your program is exported as an EXE.

    Be sure to leave any feedback/bug reports/questions in the comments below.

    Enjoy.

  • Thanks for your work on this! This is essential for making screensavers until the actual screensaver option is fixed, if that is even what it does :D

    This can be used in many applications. Thanks for being a contribution to the community!

  • Trying to pass a file path to my program. Having trouble figuring out what is going wrong on something so simple. Even using the Start Arguments I am having trouble retrieving values. Arg 1 does not seem to give me anything, but arg 2 and onward work fine? Any help from anyone else that uses this?

    I wish this came with an example :/

    That would probably help me solve my problem!

    EDIT:

    I believe I found the bug. It seems that I can't read from argument 1 no matter what. I can set several arguments in the test field and I can read all but argument 1. If I only have one argument, the program reports that there is, in fact, one argument, but I can't read it with the plugin. That's a pain. I figured I would leave one argument in the testing field and export the program as a workaround, but of course, all arguments set in the testing field are added AFTER the actual argument I want to push (a drag and drop file onto the exe to get the path). so setting argument "-test" in the test field becomes argument 2 when you actually run the program with a command line argument. Makes this plugin virtually unusable in its current state.

    Using Construct Classic r1.2

  • In typical command line programming the first argument is always that of the program name you are executing..I don't know if that is what you are referring to here. So Arg1 is the program name and Arg 2 should be your first argument.

    Or maybe its a bug...

  • Wow... this makes me feel really stupid. I didn't link to the latest version of the plugin when creating this thread, and it just so happend to include this:

    [quote:138jgkl0][FIX] - Inputting an index of "1" in the "Get argument", "Get argument name", and "Get argument value" expressions would return "NULL".

    I changed the link to the newest version, so go ahead and download that and your problem should be fixed.

    Sorry about that...

  • Oh happy day! Thank you sir, I really needed this :D

    All I had to do to get a new version was ask? You got a Construct Classic 1.3 laying around anywhere? Zing!

    EDIT:

    The plugin is ridiculously simple to use, now that it works :D

    Never the less, every good plugin needs an example. Voila!

    Drag any file onto the COMPILED caps icon and it will show you the path. If you just run a preview from Construct, you will get "NULL" because there were no arguments passed to the program.

    http://dl.dropbox.com/u/5530592/Path%20Finder.cap

    Easy as pie! This should keep me occupied for a while...

  • I don't understand you example! greyspot

  • Oh happy day! Thank you sir, I really needed this :D

    All I had to do to get a new version was ask? You got a Construct Classic 1.3 laying around anywhere? Zing!

    EDIT:

    The plugin is ridiculously simple to use, now that it works :D

    Never the less, every good plugin needs an example. Voila!

    Drag any file onto the COMPILED caps icon and it will show you the path. If you just run a preview from Construct, you will get "NULL" because there were no arguments passed to the program.

    <a rel="nofollow" href="http://dl.dropbox.com/u/5530592/Path%20Finder.cap">http://dl.dropbox.com/u/5530592/Path%20Finder.cap</a>

    Easy as pie! This should keep me occupied for a while...

    THAT was nice!

  • you would need to run your program through CMD to get any use from this right? i'm just intrigued as to when exactly you would use this! any clarification would be great.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • you would need to run your program through CMD to get any use from this right? i'm just intrigued as to when exactly you would use this! any clarification would be great.

    The most common use I see for this is being able to set file type associations with a program you make in Construct. Your program will open with the path to the file you clicked in it's arguments regardless, but without this plugin, you couldn't really make any use of it. Your program would execute without any idea of the file you tried to open.

    You could also set a few extra option when running from, yes, a command prompt or from editing the path of a shortcut.

  • Execute file - Allows you to execute an external program and supply it a set of command line arguments. Arguments are separated using Microsoft Windows standards.

    What do I actually use for the separator?

    Eg. what do I replace separator with in the following expression:

    global('CurrentPath') separator global('CurrentNewPath')

    I am executing a batch file and passing the globals as two arguments, as %1 and %2. It works fine using & as a separator if there are no spaces in the path names, but truncates to the first space where they exist.

    Thanks for any help.

  • Try to replace the space with - & nbsp; (erase the space after the ampersand)

    Just a guess.

    edit- what's the code for including a code in a post? I've tried

    but it still takes it as a space.

  • It's been a long time since I made this, so I'm not quite sure, but if you have spaces in an argument, I'm pretty sure you have to enclose it with double quotation marks.

    If that doesn't work, send a CAP my way and I'll help you work it out from there.

  • Here's the cap:

    http://dl.dropbox.com/u/22858108/SteamLink.cap

    It also requires the following file in the same directory to run:

    http://dl.dropbox.com/u/22858108/SteamLink.bat

    I wrote this little program for myself to move my selected steam games to a new location and automatically create a junction link to that location in the steam directory (in order to make more space on my Steam drive). It works fine if there are no spaces in the path names. If there is a space, it cuts everything off after it in the argument that's passed to the bat file.

    Eg. These are two arguments that are passed via CommandLine as:

    global('CurrentSteamPath') &" "& global('CurrentLinkPath'):

    1st path: E:\Steam\steamapps\common\Deus Ex

    2nd path: L:\SteamVault

    If I print the two globals they show the full correct path. However when the batch file executes it creates a junctioned link between:

    E:\Steam\steamapps\common\Deus and L:\SteamVault\Ex, when it should be between:

    E:\Steam\steamapps\common\Deus Ex and L:\SteamVault\Deus Ex.

    These are the contents of the bat file:

    echo off

    mklink /J "%1" "%2"

    pause

    Thanks for the help!

  • You need to be enclosing your arguments in quotation marks when they contain spaces. In that case, your command line expression in event 12 should look like this:

    """" & global('CurrentSteamPath') &""" """ & global('CurrentLinkPath') & """"

    And this is what your batch file should look like:

    echo off

    mklink /J %1 %2

    pause

    As a note, to display a quotation mark in a string, you need to use two of them so that Construct knows you just want to display one, rather than end the string(this is an escape character). This is why there are, like, a billion quotation marks in the above expression.

    I hope this helps. :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)