Solved how to add a constantly changing variable to a batch file

October 21, 2013 at 12:35:11
Specs: Windows 7
I was wondering how to create a variable such as hunger or thirst that is constantly depleting every (definable time) seconds. in a batch file

See More: how to add a constantly changing variable to a batch file

Report •

✔ Best Answer
October 28, 2013 at 10:41:39
#First set the starting point of your variable that you want to deplete.
#Set this right after @echo off. Including any others like hunger.
SET /A THIRST=50
#Then each thing you do could lead to a depletion of said item. In this case
# thirst.
IF %controller%==a goto room2 &SET /A THIRST=%THIRST% -5
# And you could also link &SET /A THIRST=%THIRST% -5 to many
# other commands too!
# But if you want the player to die when his thirst hits 0 you'll be better linking a if
# to every other command etc
IF %controller%==a goto room2 &SET /A THIRST=%THIRST% -5 &IF %THIRST%==0 goto dieofthirst

:dieofthirst
color 0c
cls
echo You died of thirst!
echo.
pause >nul
goto STARTGAME



#1
October 23, 2013 at 05:46:32
Manually. That's pretty much the way any language handles it, honestly.

How To Ask Questions The Smart Way


Report •

#2
October 23, 2013 at 07:08:09
ok then thanks anyway

Report •

#3
October 24, 2013 at 10:30:10
If you are moving from room to room in said game, it might be easier to tie hunger to movement instead of time.

In psudo code
for example thirst starts at 1
character changes room or direction: thirst adds 1
character buys something: thirst adds 1
character attacks strange phantasm:thirst adds 1

if thirst=5 then echo character is thirsty
if thirst=10 then echo character is dehydrated
if thirst=15 then echo character needs to drink or will collapse
if thirst=20 then echo character has collapsed would you like to try again from a previous save?

::mike


Report •

Related Solutions

#4
October 28, 2013 at 10:41:39
✔ Best Answer
#First set the starting point of your variable that you want to deplete.
#Set this right after @echo off. Including any others like hunger.
SET /A THIRST=50
#Then each thing you do could lead to a depletion of said item. In this case
# thirst.
IF %controller%==a goto room2 &SET /A THIRST=%THIRST% -5
# And you could also link &SET /A THIRST=%THIRST% -5 to many
# other commands too!
# But if you want the player to die when his thirst hits 0 you'll be better linking a if
# to every other command etc
IF %controller%==a goto room2 &SET /A THIRST=%THIRST% -5 &IF %THIRST%==0 goto dieofthirst

:dieofthirst
color 0c
cls
echo You died of thirst!
echo.
pause >nul
goto STARTGAME


Report •

Ask Question