samedi 22 juin 2019

Problem with chained if-statements in Batch

I'm working on recreating The Elder Scrolls III: Morrowind in Batch, and I'm currently programming the character creation, which includes determining a player's base stats by race and sex. I chained if-statements together in succession to require two conditions met by the selection for an attribute to be set. However, every time a race and sex are chosen, the second condition is always ignored, and the attribute is set as it should be if the character is male. I believe I may be making a simple mistake somewhere in here (as I often do). Here's the full code in case I made errors somewhere unexpected:

@echo off
:start
title Morrowind Build 6-21-19
echo Choose your character's race.
echo.
echo 1. Altmer
echo 2. Argonian
echo 3. Bosmer
echo 4. Breton
echo 5. Dunmer
echo 6. Imperial
echo 7. Khajiit
echo 8. Nord
echo 9. Orc
echo 10. Redguard
set /p p.race=
if %p.race%==1 set p.race=altmer
if %p.race%==2 set p.race=argonian
if %p.race%==3 set p.race=bosmer
if %p.race%==4 set p.race=breton
if %p.race%==5 set p.race=dunmer
if %p.race%==6 set p.race=imperial
if %p.race%==7 set p.race=khajiit
if %p.race%==8 set p.race=nord
if %p.race%==9 set p.race=orc
if %p.race%==10 set p.race=redguard
cls
echo Choose your character's gender.
echo.
echo 1. Male
echo 2. Female
choice /c 12 /n
if errorlevel 2 set p.sex=f
if errorlevel 1 set p.sex=m
if %p.race%==altmer if %p.sex%==m set /a p.strength=30
if %p.race%==altmer if %p.sex%==f set /a p.strength=30
if %p.race%==argonian if %p.sex%==m set /a p.strength=40
if %p.race%==argonian if %p.sex%==f set /a p.strength=40
if %p.race%==bosmer if %p.sex%==m set /a p.strength=30
if %p.race%==bosmer if %p.sex%==f set /a p.strength=30
if %p.race%==breton if %p.sex%==m set /a p.strength=40
if %p.race%==breton if %p.sex%==f set /a p.strength=30
if %p.race%==dunmer if %p.sex%==m set /a p.strength=40
if %p.race%==dunmer if %p.sex%==f set /a p.strength=40
if %p.race%==imperial if %p.sex%==m set /a p.strength=40
if %p.race%==imperial if %p.sex%==f set /a p.strength=40
if %p.race%==khajiit if %p.sex%==m set /a p.strength=40
if %p.race%==khajiit if %p.sex%==f set /a p.strength=30
if %p.race%==nord if %p.sex%==m set /a p.strength=50
if %p.race%==nord if %p.sex%==f set /a p.strength=50
if %p.race%==orc if %p.sex%==m set /a p.strength=45
if %p.race%==orc if %p.sex%==f set /a p.strength=45
if %p.race%==redguard if %p.sex%==m set /a p.strength=50
if %p.race%==redguard if %p.sex%==f set /a p.strength=40
if %p.race%==altmer if %p.sex%==m set /a p.intelligence=50
if %p.race%==altmer if %p.sex%==f set /a p.intelligence=50
if %p.race%==argonian if %p.sex%==m set /a p.intelligence=40
if %p.race%==argonian if %p.sex%==f set /a p.intelligence=50
if %p.race%==bosmer if %p.sex%==m set /a p.intelligence=40
if %p.race%==bosmer if %p.sex%==f set /a p.intelligence=40
if %p.race%==breton if %p.sex%==m set /a p.intelligence=50
if %p.race%==breton if %p.sex%==f set /a p.intelligence=50
if %p.race%==dunmer if %p.sex%==m set /a p.intelligence=40
if %p.race%==dunmer if %p.sex%==f set /a p.intelligence=40
if %p.race%==imperial if %p.sex%==m set /a p.intelligence=40
if %p.race%==imperial if %p.sex%==f set /a p.intelligence=40
if %p.race%==khajiit if %p.sex%==m set /a p.intelligence=40
if %p.race%==khajiit if %p.sex%==f set /a p.intelligence=40
if %p.race%==nord if %p.sex%==m set /a p.intelligence=30
if %p.race%==nord if %p.sex%==f set /a p.intelligence=30
if %p.race%==orc if %p.sex%==m set /a p.intelligence=30
if %p.race%==orc if %p.sex%==f set /a p.intelligence=40
if %p.race%==redguard if %p.sex%==m set /a p.intelligence=30
if %p.race%==redguard if %p.sex%==f set /a p.intelligence=30
echo Strength: %p.strength%
echo Intelligence: %p.intelligence%
pause
goto start

Aucun commentaire:

Enregistrer un commentaire