Solved Comparing two variables to a number

January 14, 2018 at 21:06:36
Specs: Windows 10
Hello everybody thank you for taking the time to read this. I've been working on a game in Batch for a while now. In this game you can craft things from mob drops. For example for 2x flesh you can craft a bandage. The code for this works perfectly by confirming they want to craft a bandage, then they go to a section of code that checks if they have 2x flesh if they do/don't it redirects them accordingly. My problem arises when I want something crafted from 1x bandage and 1x teeth. I tried to say something along the lines of: if %bandages% && %teeth% GEQ 1 goto craft. But that didn't work. I then tried if %bandages% GEQ 1 goto craft.1 then in craft.1 it contains: if %teeth% GEQ 1 goto craft. That didn't work either. I have the full code for all of this if you would like to see it. Any help is greatly appreciated. I just need a way to compare two variables to a number then redirect them based on those outcomes.

See More: Comparing two variables to a number

Report •

✔ Best Answer
January 16, 2018 at 02:11:44
try a double if statement:

if %flesh% GEQ 1 if %teeth% GEQ 1 goto craft.1

or more readable:

if %flesh% GEQ 1 (
if %teeth% GEQ 1 (
goto craft.1
)
)


also i've been working on a game myself for a few years now, maby reading it can help you improve yours:
text version: https://pastebin.com/qhgTGvU5
2D map version: https://pastebin.com/Rmf9t2Js

i5-6600K@4.670GHz/4.448GHz cache@1.33v | 2x4GB Crucial-DDR4-2133@ 15-15-15-31 2T 2817MHz@1.3v | ASUS Z170-K | Samsung 250GB SSD 850 EVO | MSI RX 570 4GB@1384cc&2087mc bios-powertune-mod | Corsair VS45

message edited by hidde663



#1
January 14, 2018 at 21:30:02
mebbe try: if %bandages%%teeth% geq 11 goto craft
it is better for all accumulator var.s to be undefined rather than zero, since batch interprets leading zeros as octal notation. The 'set /a' will add just as well to an undefined variable as it will to a '0'. If you play by that rule, this might work, otherwise not.

Report •

#2
January 15, 2018 at 00:25:53
Unfortunately that did not work. This has been puzzling me for awhile wish i could find a solution :(

Report •

#3
January 15, 2018 at 02:22:34
If you gid rid of the gameboy clutter, I'll look at it.
2018-01-15 17:17:40.64 GMT +7

=====================

M2 Get custom script or take private lessons


Report •

Related Solutions

#4
January 15, 2018 at 20:25:48
Okay lol, I need to compare two variables to a number.

Here is code to check if you have the right number stored in a variable to craft a item

:ItemBandage
cls
Echo.
echo Are you sure you would like to craft a bandage?
echo.
echo 1) Yes
echo.
echo 2) No
set /p input=
if %input% == 1 goto ItemBandageCheck
if %input% == 2 goto Craft

:ItemBandageCheck
cls
echo.
if %flesh% GEQ 2 goto ItemBandageCraft
if %flesh% LSS 2 goto ItemBandageError

:ItemBandageCraft
cls
echo.
set /a flesh-= 2
set /a bandages+= 1
echo You have succesfully crafted a bandage!
pause >nul
goto Craft

:ItemBandageError
cls
echo.
echo You do not have the required materials to craft this item
pause >nul
goto Craft

My problem arises when i want to use two variables to craft an item. I tried this:

:CraftHealth5
cls
echo.
echo Are you sure you would like to craft a health potion(+5)?
echo -----------------------------------------------------------
echo 1) Yes
echo.
echo 2) No
set /p input=
if %input% == 1 goto CraftHealth5Check
if %input% == 2 goto Craft

:CraftHealth5Check
cls
if %bandages% && %flesh% GEQ 1 goto CraftHealth5Complete
if %bandages% && %flesh% LSS 1 goto CraftHealth5Error

:CraftHealth5Complete
cls
set /a potion1= HealthPotion(+5)
echo You have succesfully crafted a health potion (+5)
pause >nul
goto Craft

:CraftHealth5Error
cls
echo.
echo Error in crafting item, check you have the right amount of materials!
pause >nul
goto craft

I also tried this:

:CraftHealth5
cls
echo.
echo Are you sure you would like to craft a health potion(+5)?
echo -----------------------------------------------------------
echo 1) Yes
echo.
echo 2) No
set /p input=
if %input% == 1 goto CraftHealth5Check
if %input% == 2 goto Craft

:CraftHealth5Check
cls
if %bandages% GEQ 1 goto CraftHealth5Complete.1
if %bandages% LSS 1 goto CraftHealth5Error

:CraftHealthComplete.1
cls
echo.
if %teeth% GEQ 1 goto CraftHealth5Complete

:CraftHealth5Complete
cls
set /a potion1= HealthPotion(+5)
echo You have succesfully crafted a health potion (+5)
pause >nul
goto Craft

:CraftHealth5Error
cls
echo.
echo Error in crafting item, check you have the right amount of materials!
pause >nul
goto craft


Report •

#5
January 16, 2018 at 02:11:44
✔ Best Answer
try a double if statement:

if %flesh% GEQ 1 if %teeth% GEQ 1 goto craft.1

or more readable:

if %flesh% GEQ 1 (
if %teeth% GEQ 1 (
goto craft.1
)
)


also i've been working on a game myself for a few years now, maby reading it can help you improve yours:
text version: https://pastebin.com/qhgTGvU5
2D map version: https://pastebin.com/Rmf9t2Js

i5-6600K@4.670GHz/4.448GHz cache@1.33v | 2x4GB Crucial-DDR4-2133@ 15-15-15-31 2T 2817MHz@1.3v | ASUS Z170-K | Samsung 250GB SSD 850 EVO | MSI RX 570 4GB@1384cc&2087mc bios-powertune-mod | Corsair VS45

message edited by hidde663


Report •

Ask Question