vendredi 24 mars 2017

How to call upon the last line in a .txt file in batch and use it?

I have a code for a random number generator that looks like this:

@echo off
set cycle=0
:cycle
%random% 2>nul
%random% 2>nul
set /a cycle=%cycle%+1
if "%cycle%"=="2" goto core
goto cycle
:core
set /a num="(10 * %random%) / 32768 + 1"
echo %num% >>rng.log
echo %num%
echo.
rem Code break point, Add on from here.
pause

I have this to generate a random number and put it in a .txt file, but how would I call upon the last number in the file in another batch file:

:Start
@echo off
echo Are you a [b]oy or a [g]irl?
set INPUT=
set /P INPUT=Type input: %=%
If "%INPUT%"=="b" goto boy 
If "%INPUT%"=="g" goto girl
If "%INPUT%"=="B" goto boy
If "%INPUT%"=="G" goto girl
pause
:boy
echo You have chosen boy, are you sure you want to continue? [y/n]
set INPUT=
set /P INPUT=Type input: %=%
If "%INPUT%"=="y" goto classb 
If "%INPUT%"=="n" goto Start
If "%INPUT%"=="Y" goto classb
If "%INPUT%"=="N" goto Start
pause
:girl
echo You have chosen girl, are you sure you want to continue? [y/n]
set INPUT=
set /P INPUT=Type input: %=%
If "%INPUT%"=="y" goto classg 
If "%INPUT%"=="n" goto Start
If "%INPUT%"=="Y" goto classg
If "%INPUT%"=="N" goto Start
pause
:classb
echo What class would you like to be? [s]oldier, [m]ercenary, [w]izard
set INPUT=
set /P INPUT=Type input: %=%
If "%INPUT%"=="s" goto soldier 
If "%INPUT%"=="S" goto soldier
If "%INPUT%"=="m" goto merc
If "%INPUT%"=="M" goto merc
If "%INPUT%"=="w" goto wizard
If "%INPUT%"=="W" goto wizard
pause
:classg
echo What class would you like to be? [g]hetto, [f]abulous, [w]itch, [fe]minist
set INPUT=
set /P INPUT=Type input: %=%
If "%INPUT%"=="g" goto ghetto 
If "%INPUT%"=="G" goto ghetto
If "%INPUT%"=="f" goto fabulous
If "%INPUT%"=="F" goto fabulous
If "%INPUT%"=="w" goto witch
If "%INPUT%"=="W" goto witch
If "%INPUT%"=="fe" goto feminist
If "%INPUT%"=="Fe" goto feminist
If "%INPUT%"=="fE" goto feminist
If "%INPUT%"=="FE" goto feminist
pause
:soldier
echo You woke up in the middle of a battlefield, which way do you want to go? [u]p, [d]own, [l]eft, [r]ight
set INPUT=
set /P INPUT=Type input: %=%
If "%INPUT%"=="u" goto 01 
If "%INPUT%"=="U" goto 01
If "%INPUT%"=="d" goto 0-1
If "%INPUT%"=="D" goto 0-1
If "%INPUT%"=="l" goto -10 
If "%INPUT%"=="L" goto -10
If "%INPUT%"=="r" goto 10
If "%INPUT%"=="R" goto 10
:01
echo To your left you see a soldier laying on the ground with something stuck in his side, which way do you want to go? [u]p, [d]own, [l]eft, [r]ight
Invisible.vbs "rng.bat"
set INPUT=
set /P INPUT=Type input: %=%
If "%INPUT%"=="u" goto 02 
If "%INPUT%"=="U" goto 02
If "%INPUT%"=="d" goto 00
If "%INPUT%"=="D" goto 00
If "%INPUT%"=="l" goto -11 
If "%INPUT%"=="L" goto -11
If "%INPUT%"=="r" goto 11
If "%INPUT%"=="R" goto 11

I want to use the number to randomly generate a monster or no monster at all in every room besides the first one, as I am creating a text-based RPG, how would I make it so only a few numbers generate a certain thing?




Aucun commentaire:

Enregistrer un commentaire