1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

menu batch file questions

Discussion in 'Support' started by Mezlo, May 13, 2014.

  1. Mezlo

    Joined:
    May 12, 2014
    Messages:
    18
    Likes Received:
    0
    I'm running TCC 12.11 and TCC/LE 13.06. I'm working on re-writing a game batch menu system I wrote several years ago and have 2 questions.

    First, is it possible to change the text color in a section of the window without changing the text? For example, after the menu is onscreen, can I change the color of all text in the area from row 8, col 20 to row 12, col 50?

    Second, is it possible to reference a variable name when expanding another variable? Say I have variables named "optA", "optB"and "key". If key=A, can I somehow reference "opt%key" and have it return the value of "optA"?

    Lastly, I know that @ASCII will return the ascii value of a given character. How about the reverse? Given an ascii value, how do I return the character?

    Any help with this would be appreciated. FWIW, I've been using 4DOS/4NT/TCC since 4DOS v3 or v4 and used to know a lot of little tips and tricks like this. However, I don't use it all that much anymore so have forgotten most of it. That's what happens when you get old. :)
     
    #1 Mezlo, May 13, 2014
    Last edited: May 13, 2014
  2. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,939
    Likes Received:
    30
    1. No
    2. %[opt%key]
    3. %@CHAR[N]
     
  3. Mezlo

    Joined:
    May 12, 2014
    Messages:
    18
    Likes Received:
    0
    Thanks for the help vefatica. #3 should have been obvious, I was just overlooking it in the help pages.
     
  4. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,187
    Likes Received:
    11
    Vince's #1 is semi-incorrect. The SCRPUT command allows you to write text at specific screen locations in a specific color.
    So if you know the text you can re-write it in a different color. You can also use the SCREEN command and use ANSI escape sequences to set the color.
    This writes "Hello World" in white fg on green bg at row 40 column 80
    Code:
    scrput 40 80 bri white on green Hello World
    screen 40 80 ^e[37;42;1mHello World
    
     
  5. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    The @READSCR function will let you get the existing text to be recolored; you'll have to loop to read several lines.
     
  6. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    But beware of special characters you need to read, e.g., percent signs (%). SETDOS option /X is your friend,,,
    BTW, I remembered there is a @READSCR function, but had overlooked it in Variable Functions Listed by Category - it's only in the System status category, which is only remotely related.
     
  7. Mezlo

    Joined:
    May 12, 2014
    Messages:
    18
    Likes Received:
    0
    @samintz - I've been using screen/scrput to generate the menus but it makes them hard to read within the batch file itself. That's why I was hoping I could output the menu in one color then go back and colorize sections of it.

    @JohnQSmith & @Steve Fabian - Thanks for the suggestion and warning. I'll take a look at @READSCR and see if that will accomplish what I want. It sounds promising.

    In case anyone's interested I've attached a screenshot of one of the menus.
     

    Attached Files:

  8. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,301
    Likes Received:
    39
    Heh. That brings back memories. I once spent unconscionable hours at work "testing the network" with those. Wasn't entirely work-unrelated, either. Back in the days when cache memory was provided by discrete SRAM chips, I found that Doom did a better job at finding flaky chips than the expensive memory-test software we bought.

    It wouldn't be hard to write functions to read, fill, save, and restore color attributes from the screen buffer. I'll let Vince have first crack at that project, as it looks like a natural fit for 4Console.
     
    Mezlo likes this.
  9. Mezlo

    Joined:
    May 12, 2014
    Messages:
    18
    Likes Received:
    0
    @Charles Dye - I figured somebody would get a chuckle out of that. :)
     
  10. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    I looked at the menu. With each of several sections of the screen containing unrelated menu segments, I would write a batch file which has parameters: foreground (text) color, background color. top eow, left column, start selection code (1,6,A,etc), number of selectable texts, list of selection strings. Invoke this file for each section. Makes it much more readable!
     
  11. Mezlo

    Joined:
    May 12, 2014
    Messages:
    18
    Likes Received:
    0
    @Steve Fabian - Here's how I'm doing it as of last night:
    Code:
    set FG1=^e[31;1m
    set FG3=^e[33;1m
    set FG7=^e[37;0m
    set menu1=Ultimate Doom
    set menu1game=ultimate-doom
    set menu2=DOOM II
    set menu2game=doom2
    set menuA=Chex Quest 3
    set menuB=Doom 64: Absolution+Outcast
    ...
    screen  8  3 %FG7%1) %FG1%%menu1
    screen  9  3 %FG7%2) %FG1%%menu2
    screen  8 46 %FG7%A) %FG3%%menuA
    screen  9 46 %FG7%B) %FG3%%menuB
    ...
    inkey /C /K"123456789ABCDEFGHIJQ" /P /X /W20 %%choice
    set game=%[menu%choice%game]
    if "%game%"=="" goto start
    set gamename=%[menu%choice]
    set center=%@eval[(80-%@len[%gamename])/2]
    scrput 20 %center bri gre on bla %gamename
    
    Of course, there's a lot more to the file but that's the menu generation stuff. I used to generate it 1 line at a time similar to:
    screen 8 3 %FG7%1) %FG1%Ultimate Doom %FG7%A) %FG3%Chex Quest 3
    but that was a PITA getting everything aligned, not to mention re-arranging items.

    I like your idea of a separate batch file to generate the menu. In fact, I was already thinking about the best way to do something like that.
     
    #11 Mezlo, May 14, 2014
    Last edited: May 16, 2014
  12. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    I will respond in a little while.
     
  13. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    680
    Likes Received:
    8
    This is a bar menu batch file that I made a while back.

    http://jpsoft.com/forums/threads/plugin-status-load-unload-via-bar-menu.1852/

    Not exactly what you are looking for, but it does show how I change the colours on the bar menu. It may give you a few ideas for your own batch file.

    Joe
     
  14. Mezlo

    Joined:
    May 12, 2014
    Messages:
    18
    Likes Received:
    0
    So last night I spent almost an hour troubleshooting not having any sound in Doomsday. Long story short, I saw Joe's reply before I left work and saw unset * in his script and thought that'd be a good idea. I remoted into my home PC, added it to the file and saved, then disconnected and promptly forgot about it. Later when I got home I started making more changes and suddenly I didn't have any sound in Doomsday! I eventually remembered adding the unset command, removed it, and sound started working again. :)
     
  15. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,301
    Likes Received:
    39
    BLASTER ?
     
  16. Mezlo

    Joined:
    May 12, 2014
    Messages:
    18
    Likes Received:
    0
    No, there's not a BLASTER variable, just the standard Windows ones so I'm not sure which one caused the issue. I thought it was a Doomsday issue so I uninstalled and reinstalled, reset all settings, etc trying to fix it. At least it gave me something else to do besides mowing. :)

    Anyway, tonight I think I might try moving all of my menu* variables into a menu array instead, although I'm not sure what advantage/disadvantage that might provide (other than letting me play with arrays). :)
     
    #16 Mezlo, May 15, 2014
    Last edited: May 15, 2014
  17. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    680
    Likes Received:
    8
    Note also that I begin most of my batch files with SETLOCAL and end them with ENDLOCAL. That way, when the batch file is finished, unset * is undone.

    From the help file;
    Code:
    UNSET can be used in a batch file, in conjunction with the SETLOCAL and ENDLOCAL commands, to clear the environment of variables that may cause problems for applications run from that batch file.
    Just a habit that I have developed.

    Joe
     
  18. Mezlo

    Joined:
    May 12, 2014
    Messages:
    18
    Likes Received:
    0
    I always use SETLOCAL/ENDLOCAL as well.
     
  19. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    I always use SETLOCAL, but as a lazy gun I trust that termination of a batch file automatically performs ENDLOCAL. In fact it is safe, because if it required the explicit ENDLOCAL but interrupted would screw up everything. But Rex made us safe from that.
     
  20. Mezlo

    Joined:
    May 12, 2014
    Messages:
    18
    Likes Received:
    0
    OK, I'm going nuts. I've switched to array variables and have defined menu[49,1] through menu[55,1] like so:

    Code:
    unsetarray /q menu
    setarray menu[100,10]
    set menu[49,1]=Ultimate Doom
    set menu[50,1]=DOOM II
    set menu[51,1]=Final DOOM: Plutonia Experiment
    set menu[52,1]=Final DOOM: TNT Evilution
    set menu[53,1]=Heretic: Shadow of the Serpent Riders
    set menu[54,1]=HeXen: Beyond Heretic
    set menu[55,1]=HeXen: Kings of the Dark Citadel
    set row=8
    for /l %P in (49,1,57) (
      if defined menu[%P,1] screen %row 3 %FG7%%@char[%P]^) %FG1%%menu[%P,1]
      set row=%@inc[%row]
    )
    This should print something onscreen for values of %P from 49-55 and nothing when %P is 56 or 57. Instead it doesn't print anything onscreen. However, if I change it to not defined then it prints something onscreen for all values (see screen shot). It's like the logic is reversed. What am I missing to make this work as desired?
     

    Attached Files:

    #20 Mezlo, May 15, 2014
    Last edited: May 16, 2014
  21. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    if defined reports the status of individual environment variables, not individual elements of arrays. Before arrays were invented, I had used things like menu_49 and menu_50, etc. You may want to use that approach.
     
  22. Mezlo

    Joined:
    May 12, 2014
    Messages:
    18
    Likes Received:
    0
    I was tired last night when I was working on this. I woke up this morning and realized that what's happening is it isn't referencing menu[%P,1] correctly. I changed it to if not "%menu[%P,1]"=="" and it is working as expected. I always thought if defined was equivalent to that (it even says so in the help file) but apparently not in this case.
     
  23. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
  24. Mezlo

    Joined:
    May 12, 2014
    Messages:
    18
    Likes Received:
    0
    I"m running TCC 12.11. The 2nd paragraph of DEFINED states "Note: GOSUB variables and internal variables always fail the DEFINED test." There's no mention of array variables. :)
    However, since I've been working on this I've been considering purchasing the upgrade but what I have works so I haven't been able to justify the cost.
     
  25. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    Sorry, you are correct, I should check V12 and not V16, I even have an alias (driving a batch file) since V10 to do it. Apparently. even though arrays were available since the earliest TCC (build 9), nobody complained about that phrase missing before version 16. Of course, an old hat would say "not mentioned explicitly, not available".
    Download the free trial, open the V16 tcmd.chm. the first chapter (after the Overview) What's new in Version 16 and subchapters for each version from 15 back to 10. If I remember correctly, each chapter is the increment to the next version. Most software uses this method so they need never be updated.
    BTW, I always use the conditional expression (when DEFINED is inapplicable)
    Code:
    %@len[xxx] GT 0
    to check instead of string matching, on the assumption that just counting characters in xxx is faster than a match, though I never validated my assumption.
     
  26. MaartenG

    Joined:
    Aug 3, 2016
    Messages:
    355
    Likes Received:
    8
    Yesterday I found a diskette (!!) with on it a menu script I wrote a long time ago.
    It's cursor driven with a built-in screensaver.

    It had Goto's everywhere without any Gosub (in my defence: it was my second year of computing; still a lot to learn...)
    So, the script was happily jumping around, but I was not. So I rewrote it a little.
    There is still a lot of room for improvement (using Switch for example), but maybe it can give you some inspiration.

    Personally, I like the
    Code:
    TEXT| GOSUB %ROUTINE
    part: create a "database" once and use it many times for different purposes.

    Down below are 2 other (short, I promise!) menu scripts I found on the same diskette.

    Code:
    @echo off
    setlocal
    pushd
    
    REM Default menu entry
    set rij=5
    set kolom=45
    
    :START
    set ROUTINE=BUILDMENU
    GOSUB ENTRIES
    
    
    :WIJZER
    scrput %rij %kolom WHI ON RED %@readscr[%rij,%kolom,23]
    set screen=15
    setdos /s0:0
    
    :KLOK
       screen 1 1
       scrput 24 10  whi on bla Over %screen seconden wordt de screensaver actief ...
       SET TOETS=DUMMY
       SCRput 0 48 BRI YEL on BLU [ %_DATE   %_TIME ]
       INKEY /K" [Esc][Up][Down][Left][Right][Enter]" /W1 /P %%toets
       if "%@ASCII[%toets]"="27" GOTO STOP
       if %toets=@80 goto NEER
       if %toets=@72 goto OP
       if %toets=@75 goto LINKS
       if %toets=@77 goto RECHTS
       if %toets=@28 goto KEUZE
       set screen=%@DEC[%screen]
    
       REM Start Screensaver
       if %screen=0 goto scherm
    GOTO KLOK
    
    
    :NEER
       if %rij eq 17 goto wijzer
       scrput %rij %kolom bla on CYAN %@readscr[%rij,%kolom,23]
       set rij=%@eval[%rij+2]
    goto WIJZER
    
    
    :OP
       if %rij eq 3 goto wijzer
       scrput %rij %kolom bla on CYAN %@readscr[%rij,%kolom,23]
       set rij=%@eval[%rij-2]
    goto WIJZER
    
    
    :RECHTS
       if %rij eq 17 .and. %kolom eq 45 goto wijzer
       scrput %rij %kolom bla on cyAN %@readscr[%rij,%kolom,23]
       set rij=%@eval[%rij+2*(%kolom\40)]
       set kolom=%@eval[(30+%kolom)%%60]
    goto WIJZER
    
    
    :LINKS
       if %rij eq 3 .and. %kolom eq 15 goto wijzer
       scrput %rij %kolom bla on CYAN %@readscr[%rij,%kolom,23]
       set kolom=%@eval[(30+%kolom)%%60]
       set rij=%@eval[%rij-2*(%kolom\40)]
    goto WIJZER
    
    
    :KEUZE
       set ROUTINE=ACTIE
       GOSUB ENTRIES
    GOTO START
    
    
    :STOP
       SETDOS /S100:10
       UNSET TOETS
       UNSET RIJ
       UNSET KOLOM
       UNSET ROUTINE
       popd
       CLS cyan on blu
    QUIT
    
    
    
    
    
    
    ::=============[ ROUTINES ]===========================
    
    :ENTRIES
    TEXT| GOSUB %ROUTINE
      3 15  @MAH-JONGG@ (IN SHANGHAI DE.EXE)
      5 15  @SNEAKY@ (IN SLANG1 SNEAKY.EXE)
      7 15  @FLIPPER@ (IN FLIPPER TRISTAN)
      9 15  @BLOCK OUT@ (in blockout bl)
      11 15 @KILOBLASTER@ (IN KILO CALL KILO.BAT)
      13 15 @BRIX@ (IN BRIX BRIX)
      15 15 @KLAVERJASSEN@ (IN KLAVER KLAVER)
      17 15 @MAANLANDING@ (IN MAANLAND LM)
      3 45  @MAH-JONGG 2@ (IN MAHJONG2 GO)
      5 45  @SNEAKY 2@ (IN SLANG2 SNEAKY.EXE)
      7 45  @FLIPPER 2@ (IN EPIC PINBALL)
      9 45  @TETRIS@ (IN TETRIS etetris.exe)
      11 45 @AUTORACE@ (IN AUTORACE 4D)
      13 45 @BRIX 2@ (IN BRIX2 BRIX1)
      15 45 @RAD VAN FORTUIN@ (IN RADFORT RVF.EXE)
      17 45 @ROLLERBALL@ (CLS^IN BALLGAME BALGAME2)
    ENDTEXT
    RETURN
    
    REM ===================================================
    
    :BUILDMENU
       cls bri cyan on blue
       drawbox 0 10 22 74 2 bri yel on blu
       SCRPUT 1 37 red on white SPELLEN MENU
       SCRPUT 20 15 blu ON WHI Û Verplaatsen:pijl Û Stoppen: Esc Û Uitvoeren: Enter Û
    
       for %x in (@CON) (
        scrput %@word["@",0,%x] black on cyan .  %@word["@",1,%x]%@REPEAT[ ,%@EVAL[19-%@LEN[%@word["@",1,%x]]]].
       )
    RETURN
    
    REM ===================================================
    
    :ACTIE
       FFIND /KM /T"%RIJ %KOLOM"| %@WORD["@",2,%@LINE[CON:,0]]
    RETURN
    
    REM ===================================================
    
    :SCHERM
       cls BLA on bla
       scrput %@RANDOM[1,24] %@RANDOM[1,45] %@WORD[%@RANDOM[0,6], MAG BLU CYA GRE YEL RED WHI] on bla Willekeurige toets voor spellenmenu
       scrput %@RANDOM[1,24] %@RANDOM[1,45] %@WORD[%@RANDOM[0,6], MAG BLU CYA GRE YEL RED WHI] on bla %_time
       INKEY /W2 %%SCH
       IF "%SCH"=="" GOTO SCHERM
       UNSET SCH
    goto START
    
    REM ===================================================
    
    :SCHERM4
       scrput %@RANDOM[0,24] %@RANDOM[0,79] BLA on bla ÿ
       INKEY /W0 %%SCH
       IF "%SCH"=="" GOTO SCHERM4
       UNSET SCH
    goto START
    

    BTW: I also found 2 other menu-scripts:

    First one: for evey line: show the left part; execute the right part

    Code:
    @TEXT|%@SUBSTR[%@SELECT[CON,1,54,15,76,[  FORMATTEER A: ]],23,80]
    -  HD-FLOP          -     (format a:/u/autotest^beep 400 2 800 2)
    -  DD-FLOP          -     (format a:/u/f:720/autotest^beep 400 2 800 2)
    -  HD-FLOP snel     -     (sf a:/q/a^beep 400 2 800 2)
    -  DD-FLOP snel     -     (sf a:/q/a/f:720^beep 400 2 800 2)
    ------ EINDE --------      QUIT
    ENDTEXT
    
    Second one: For every (game) directory: Show foldernames; goto folder and execute what's in Descript.ION of the folder

    Code:
    (dir/ad/b/i"*"|set D=%@FULL[%@SELECT[CON,1,54,15,76,[  %@descript[%_DNAME] ]]])>& nul
    IN %D CALL %@DESCRIPT[%D]
    
     

    Attached Files:

Share This Page