我是stackOverflow的新手。我有个问题。为什么我的代码不起作用......它嵌套了if语句,应该有效...我很难过。你应该有钱,一个家(1到3型)和电话。电话是问题所在。 callLine用于告诉每次调用callText时将显示哪一行。每次在Calling2中调用它时,它会自动加1。只要它达到某个数字,它就会将callText(显示的文本)更改为其他内容。但是使用callWho变量(work或home)时,还需要检查它。这是:
@ echo off
set money=10000
set house=1
set item=Phone
set /a callLine=0
setlocal enabledelayedexpansion
echo Hello there! I am Joe, and I am the mayor of Redcrest Town.
pause
cls
echo I'm so happy to see another resident move into the Redcrest Town.
echo So, will you do me a favour and tell me your name?
set /p Name=
cls
echo Well then, %name%! Welcome!
pause
cls
echo I hope you have a great time here. You have 10,000 dollars, and a small house.
echo Please enjoy your time here!
pause
cls
:UsePhone
echo Money: %money%
echo.
echo You are using your phone. This will cost money, each time you call.
echo.
echo.
echo __i [CONTACT LIST]
echo ^|---^| [1: HOME ]
echo ^|[_]^| [2: WORK ]
echo ^|:::^|
echo ^|:::^|
echo `\ \
echo \_=_\
set /p callWho=Select Number:
if %callWho% == 2 goto Calling
echo %callText%
pause
:Calling
cls
echo Calling......
ping localhost -n 4 >nul
:Calling2
if callLine == 0 if %callWho% == 2 set callText="Hello? Is this %name%?"
if callLine == 1 if %callWho% == 2 set callText="Oh hello! It's really nice to talk to you again."
if callLine == 2 if %callWho% == 2 set callText="Well, I will see you soon, %name%! Bye!"
if callLine == 3 if %callWho% == 2 set callText="END"
set /a callLine = callLine + 1
cls
echo __i
echo ^|---^|
echo ^|[_]^| PHONE: %callText%
echo ^|:::^|
echo ^|:::^|
echo `\ \
echo \_=_\
ping localhost -n 5 >nul
if %callText% == "END" goto UsePhone
goto Calling2
我一直在崩溃:。这时出乎意料.... 真的很不寻常。
答案 0 :(得分:1)
你忘记了callLine
周围的%%。
:Calling2
if %callLine% == 0 if %callWho% == 2 set callText="Hello? Is this %name%?"
if %callLine% == 1 if %callWho% == 2 set callText="Oh hello! It's really nice to talk to you again."
if %callLine% == 2 if %callWho% == 2 set callText="Well, I will see you soon, %name%! Bye!"
if %callLine% == 3 if %callWho% == 2 set callText="END"
set /a callLine = callLine + 1
使用if
语句测试变量时,必须将变量括在%%