Announcement

Collapse
No announcement yet.

How to build a compile options menu

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to build a compile options menu

    How To Build A Compile Options Menu

    Most programs (especially revolving around quake modification) allow you ways to run external batch/bash scripts from within the program. Usually this option is found in the shortcut menu, but not always.

    My philosophy is that this is the gateway to connecting unrelated programs to serve the same purpose. For instance, Notepad++ has nothing to do with Quake but via external scripts I managed to tie these things together in a way that makes sense.

    This concept can be used in many different programs and you are really only limited by your imagination as to how things can be tied together. The following tutorial serves as an example as well as some deeper knowledge of what can be accomplished in a bat.

    I would like to note that I knew none of this before I needed to know it and maybe this is even all I know. This information is already out there in various parts, this just brings it together and provides a solid implementation. I would also like to note that my example is a windows bat and would need to be modified by people that know more than I on how to make it a bash.

    part 1: I do this every time

    Code:
    @ECHO off
    This line turns off reporting in the console. We want it to be real clean and only output the information we want. We'll turn this back on when we aren't changing directories

    Code:
    cd /d %~dp0
    that code simply says "change the working directory to the one that this bat is in". We do this because np++ for example is in another directory and when we call this script, the potential is there for the np++ directory to be the current one. BY starting off with changing the directory to the .bat one, we know exactly where we are on the system and we can navigate with more confidence.

    Code:
    cls
    Really, we just want black.

    code so far:
    Code:
    @ECHO off
    cd /d %~dp0
    cls
    part 2: decisions, decisions

    This part may not apply to your needs. This part is to illustrate if there were 2 or more root possibilities to be addressed. In the case of my QC environment, it has to be determined if you want to compile svqc or csqc. That is a root decision that needs to be made, and it needs to be made in a way that it is always definitely decided. We can achieve this with a simple if statement.

    Code:
    if "%1"=="" set type=SVQC
    if not "%1"=="" set type=%1
    I guess I should back-up just a little bit. %1 represents the first switch that you call your bat with. So let's say we are making menu.bat. We could call menu.bat from a shortcut menu with a switch like:

    menu.bat SVQC

    %1 would equal SVQC in this example. If we added more switches, the numbers go up (%2 %3 etc). With that information you can read the above much easier, it says:

    if the first switch is empty set a variable named type to be SVQC
    if not the first switch is empty set a variable named type to the switch value


    to shorten that even more it says
    if switch is empty assign a default value else assign the switch value.

    ok so now we have a var named type and it has a value. We should probably make another var that holds the engine

    Code:
    set eng=darkplaces.exe
    done. Note that there is no spaces after the =. This is important.

    eng= darkplaces.exe

    is not the same as

    eng=darkplaces.exe

    the first will make this var " darkplaces.exe" which will look like this in a path "/Quake/%20darkplaces.exe

    part 3: throw out the anchor! (I know, these are getting dumb)

    Making script anchors is how we are going to determine all of the rest of this. Script anchors (my made up name for them) allow us to tell our script to go directly to a different part of our script. In this way we can create expressions that allow us to guide the flow of input.

    our script so far
    Code:
    @ECHO off
    cd /d %~dp0
    cls
    
    if "%1"=="" set type=SVQC
    if not "%1"=="" set type=%1
    set eng=darkplaces.exe
    now lets add a script anchor
    Code:
    :START
    yup it's that simple now anything we put below it and before another anchor will be exclusive to this anchor being called. Let's start building our menu.

    Code:
    :START
    ECHO.
    ECHO 1. Open Log
    ECHO 2. Start Quake
    ECHO 3. Start a specified map from ID1 folder
    ECHO 4. Start a specified map from a specified folder
    ECHO 5. Close
    All that does is output our menu options. In itself it has no power to do anything. I think the only line that isn't self explanatory is "ECHO.". That is code for new line.

    Now lets address the actual meat and potatoes
    Code:
    set /p choice=Choose a number and press enter:
    if not "%choice%" =="" set choice=%choice:~0,1%
    Imma have to address these two lines before going on because they are sort of complex. When using the /p expression before a var you are setting, you are saying that the values will come from keyboard input. The next line I am saying "If choice is not empty then set choice to itself if it s not 0 and only grab the first character." Imma tell ya, that's some anal code I wrote.

    Soo this part is simply making a new variable named choice that we can set with input and then checks to make sure it is set and if it is set properly (sorta). Now we are going to check for the possibilities that we expect

    Code:
    if "%choice%"=="1" goto COL
    if "%choice%"=="2" goto CSQ
    if "%choice%"=="3" goto CSQSMID1
    if "%choice%"=="4" goto CSQSMSF
    if "%choice%"=="5" goto CC
    ECHO "%choice%" is not valid, try again.
    We simply check if choice has been assigned a number we expect and then we declare what script anchor we should jump to. Don't be discouraged by the crazy string of capital letters. Those are the names I chose for my script. You can use whatever names you want. To give you an idea of how I chose those names

    CSQSMSF - Compile and Start Quake from a Specific Map and a Specific Folder. It's just the first letter of all the most important words of its description.

    Moving on, if none of the conditions we expect are met, then it will not redirect to a script anchor and therefore reach the line that says their choice is not valid. I would also like to note that I am putting all of these vars in quotes because that casts them to a string and I then know that I will never have the problem of like values not matching up just because one thing is the actual number 5 and a different thing is the string "5".

    part 4: Are we ever gonna get it started?

    OK we have addressed many things. We have kept a clean board while we change the directory, then we displayed a menu, now we even have the decision maker for the menu, but if you were to test right now, nothing would happen . this is because we still have a very long way to go.

    Let's look at our current script
    Code:
    @ECHO off
    cd /d %~dp0
    cls
    
    if "%1"=="" set type=SVQC
    if not "%1"=="" set type=%1
    set eng=darkplaces.exe
    
    :START
    ECHO.
    ECHO 1. Open Log
    ECHO 2. Start Quake
    ECHO 3. Start a specified map from ID1 folder
    ECHO 4. Start a specified map from a specified folder
    ECHO 5. Close
    
    set /p choice=Choose a number and press enter:
    if not "%choice%" =="" set choice=%choice:~0,1%
    if "%choice%"=="1" goto COL
    if "%choice%"=="2" goto CSQ
    if "%choice%"=="3" goto CSQSMID1
    if "%choice%"=="4" goto CSQSMSF
    if "%choice%"=="5" goto CC
    ECHO "%choice%" is not valid, try again.
    OK now we can get down to making all those script anchors that we promised our choice var, but right before we do that we are going to tell our script to start.

    Code:
    goto START
    yup, that's it. Now if you ran it you would get the menu and the menu would even work all the way up to the point of actually going to those script anchors that don't exist yet. Lets define them

    Code:
    :COL
    fteqcc.exe -srcfile %type%/progs.src
    fteqcc.log
    EXIT
    By explaining this one, I will mostly explain the others. First off, we started by changing the working directory to the one this bat is in. That should be the same directory as fte, so things are real simple. We just call fte. Fte can accept a switch that tells it where the source file is. We also began by setting the var type, what I was actually setting was the name of the folder I need to start in, depending on which type of qc is being compiled. So, now I use that var to establish a path. Once fte finishes compiling, the log file will be opened. Hence our anchor COL (compile and open logs). Then everything will quit. There is nothing more to do.

    Code:
    :CSQ
    fteqcc.exe -srcfile %type%/progs.src
    cd ..\..
    %eng%
    EXIT
    yet again we are just using that same compile line for fte. We will use it in every single anchor cause the whole point of this script is to compile a qc and then do something else. the next line is to back-up 2 directory levels (which is where the engine should be). We stored our engine in the eng var at the top of the script, so now we can just use our var. This means we only have to change where it is set at the top of the script and all the rest will follow suit, should we ever decide to use a different engine.

    Code:
    :CSQSMID1
    set /p map=type the name of your map and press enter
    fteqcc.exe -srcfile %type%/progs.src
    cd ..\..
    %eng% +map "%map%"
    EXIT
    This is just an exaggeration of the last one. We create a keyboard input var named map, then we compile, change directories and start darkplaces with the map switch set.

    Code:
    :CSQSMSF
    set /p game=type the name of your game folder and press enter
    set /p map=type the name of your map and press enter
    fteqcc.exe -srcfile %type%/progs.src
    cd ..\..
    %eng% -game "%game%" +map "%map%"
    EXIT
    and yet another exaggeration, we do everything we did above but we add an input for the game folder.

    Code:
    :CC
    fteqcc.exe -srcfile %type%/progs.src
    EXIT
    and our final anchor (compile and close). Let's see our completed script

    Code:
    @ECHO off
    cd /d %~dp0
    cls
    
    if "%1"=="" set type=SVQC
    if not "%1"=="" set type=%1
    set eng=darkplaces.exe
    
    :START
    ECHO.
    ECHO 1. Open Log
    ECHO 2. Start Quake
    ECHO 3. Start a specified map from ID1 folder
    ECHO 4. Start a specified map from a specified folder
    ECHO 5. Close
    
    set /p choice=Choose a number and press enter:
    if not "%choice%" =="" set choice=%choice:~0,1%
    if "%choice%"=="1" goto COL
    if "%choice%"=="2" goto CSQ
    if "%choice%"=="3" goto CSQSMID1
    if "%choice%"=="4" goto CSQSMSF
    if "%choice%"=="5" goto CC
    ECHO "%choice%" is not valid, try again.
    
    goto START
    
    :COL
    fteqcc.exe -srcfile %type%/progs.src
    fteqcc.log
    EXIT
    
    :CSQ
    fteqcc.exe -srcfile %type%/progs.src
    cd ..\..
    %eng%
    EXIT
    
    :CSQSMID1
    set /p map=type the name of your map and press enter:
    fteqcc.exe -srcfile %type%/progs.src
    cd ..\..
    %eng% +map "%map%"
    EXIT
    
    :CSQSMSF
    set /p game=type the name of your game folder and press enter:
    set /p map=type the name of your map and press enter:
    fteqcc.exe -srcfile %type%/progs.src
    cd ..\..
    %eng% -game "%game%" +map "%map%"
    EXIT
    
    :CC
    fteqcc.exe -srcfile %type%/progs.src
    EXIT
    I hope this helps spur some creativity and maybe give you an understanding that you didn't already possess.
    Last edited by MadGypsy; 05-01-2013, 01:27 PM.
    http://www.nextgenquake.com

  • #2
    Extended:

    You may have noticed that our compile options were completely dependent on the options that fte and darkplaces provide. I simply went through the list (that I was aware of) and added each possibility to the script above it, one at a time. What I mean to say is, each script anchor is the guts of the one below it, which just adds one more feature. There is a bit of untruth in that if you count the very last option, but I'm sure you understand the spirit of what I am saying.

    So you see, there really is no guess work. I merely tied together everything (that I knew of) that was already there. In a sense, the script wrote itself. If you are considering to build some similar thing for another program, you should consider the options that are provided by what it is that you are tying together. This will set you on the path as to what you need to allow.
    http://www.nextgenquake.com

    Comment

    Working...
    X