Rpg assistance

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
gingerbread
Posts: 4
Joined: 04 Jan 2018 19:56

Rpg assistance

#1 Post by gingerbread » 04 Jan 2018 20:32

I'm obviously new to batch and I'm having some issues. Anyway I need to make an RPG using batch for one of my classes and I needed assistance with shop mechanics.
For the shop I'm trying to use inequalities to determine if an item can be purchased, however the window quits without explanation whenever I run it. Fairly certain it's because of the way I'm using variables but haven't found anything telling me the proper way yet.
Before you roast me too hard, keep in mind:
I know I'm not doing it the most efficient way possible
This is one chunk I'm testing from a larger game I'm creating
There are probably issues in other areas besides just variables that I don't know about

Code: Select all

@echo off
set /a money=2000
set /a medikit=0
:shop
cls
echo Welcome to the shop
echo Current Balance %money%
echo.
echo [Medikit] 100
echo.
echo [Inventory]
set /p input=What would you like to buy?:
if %input%==Medikit (
set/a cost=100
goto buymed)
if %input%==Inventory (
goto inventory)

:buymed
if %money%GEQ%cost% (
set /a medikit+=1
set /a money-=cost
echo Thanks for your Purchase
pause
goto shop) else (
echo Error insuffienct funds
pause
goto shop)

:inventory
echo Inventory
echo.
echo Medikits x%medkit%
echo.
pause
goto shop
I'd appreciate direct assistance or guidance to a source where I can learn it myself.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Rpg assistance

#2 Post by penpen » 05 Jan 2018 07:01

I think the main error is caused by this line:

Code: Select all

if %money%GEQ%cost% (
"%money%GEQ%cost%" should be handled as one token, because there is no delimiter present.
Just add spaces "around" the "GEQ":

Code: Select all

if %money% GEQ %cost% (
I also think there is a flaw with displaying your inventory:
Better use %medikit% instead of %medkit%.


penpen

gingerbread
Posts: 4
Joined: 04 Jan 2018 19:56

Re: Rpg assistance

#3 Post by gingerbread » 05 Jan 2018 07:39

Thanks for the help, code works fine now

gingerbread
Posts: 4
Joined: 04 Jan 2018 19:56

Re: Rpg assistance

#4 Post by gingerbread » 05 Jan 2018 12:29

Previous issue resolved, new problem has arisen. Trying to make weapon system, the concept of the system is to assign a numerical value and a name to the value. I'm using a similar code to this to equip and check weapons.

Code: Select all

@echo off
set /a num=1
:pick
cls
echo Pick a number
echo [1]
echo [2]
echo [3]
echo [4]
echo [Recall]
set /p input=:

if %input%==1 (
echo You selected 1
set /a num=1
pause
goto pick)

if %input%==2 (
echo You selected 2
set /a num=2
pause
goto pick)

if %input%==3 (
echo You selected 3
set /a num=3
pause
goto pick)

if %input%==4 (
echo You selected 4
set /a num=4
pause
goto pick)

if %input%==Recall goto recall

:recall
::in the final product I would assign names to the numerical values
if %num%==1 (
echo You selected 1 last time
pause
goto pick)

if %num%==2 (
echo You selected 2 last time
pause
goto pick)

if %num%==3 (
echo You selected 3 last time
pause
goto pick)

if %num%==4 (
echo You selected 4 last time
pause
goto pick)
The previous code works as intended, after picking a variable and entering recall it will display the recall.
The code below will close unexpectedly when executing the Check command.
After testing many variations of the code below I figured that the problem lies within the if commands, however not exactly sure what the problem is.

Code: Select all

@echo off
set /a weapon=1

:equip
cls
echo Choose a weapon
echo.
echo [Shotgun]
echo.
echo [Rifle]
echo.
echo [Check] current weapon
set /p input=Equip:

if %input%==Shotgun (
echo Shotgun Equipped
set /a weapon=2
pause
goto equip)

if %input%==Rifle (
echo Rifle Equipped
set /a weapon=3
pause
goto equip)

if %input%==Check (
echo Checking Equipped weapon
pause
goto gunstats)

:gunstats
echo Displaying Weapon Stats
pause
if /a %weapon%==1 (
echo No weapon Equipped
pause
goto equip)

if /a %weapon%==2 (
echo Shotgun Equipped
pause
goto equip)

if /a %weapon%==3 (
echo Rifle Equipped
pause
goto equip)
If you direct me to where I went wrong that'd be great, thanks and any advice on coding in batch would be appreciated.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Rpg assistance

#5 Post by Squashman » 05 Jan 2018 12:34

The if command does not have an /a option.

Code: Select all

if /a %weapon%==1 

gingerbread
Posts: 4
Joined: 04 Jan 2018 19:56

Re: Rpg assistance

#6 Post by gingerbread » 06 Jan 2018 07:29

Thanks for pointing that out, simple error that I missed in hindsight but its working fine now.

Post Reply