2014-05-25 92 views
1

我正在尝试在Batch/CMD中创建RPG游戏。我想这样做,以便当用户输入一个不是列出的数字时,它只是从最后一个标记中重新加载。下面是代码:If/Else Statements In Batch

if %1st%==1 %atk%+25 
if %1st%==2 %def%+25 
if %1st%==3 %hp%+25 
if %1st%==4 %iq%+25 
if %1st%==5 %luck%+25 

if not %1st%==1 goto 1st 
if not %1st%==2 goto 1st 
if not %1st%==3 goto 1st 
if not %1st%==4 goto 1st 
if not %1st%==5 goto 1st 
+0

OK。什么是或不在工作? – ClickRick

+0

它使程序崩溃而不是回到最后一个标记。 – Woops

回答

2

这是一个很好的做法,是不会有你的变量以数字开头,为%1手段传递到脚本的第一个参数。如果您没有将任何参数传递给脚本,解释器将看到这些语句为if not st%==1 goto 1stif st%==1 %atk%+25,这些语句无效。

您需要替换所有%1st%与提议%first%,其余如下:
%2nd%%second%
%3rd%%third%
%4th%%fourth%
%5th%%fifth%
%6th%%sixth%
%7th%%seventh%
%8th%%eighth%
%9th%%ninth%

这里是你与上述变化代码:

if %first%==1 %atk%+25 
if %first%==2 %def%+25 
if %first%==3 %hp%+25 
if %first%==4 %iq%+25 
if %first%==5 %luck%+25 

if not %first%==1 goto first 
if not %first%==2 goto first 
if not %first%==3 goto first 
if not %first%==4 goto first 
if not %first%==5 goto first 

而且我不知道你是如何添加值,这里是一个修改建议用set /a命令:

if %first%==1 set /a atk=%atk%+25 
if %first%==2 set /a def=%def%+25 
if %first%==3 set /a hp=%hp%+25 
if %first%==4 set /a iq=%iq%+25 
if %first%==5 set /a luck=%luck%+25 

if not %first%==1 goto first 
if not %first%==2 goto first 
if not %first%==3 goto first 
if not %first%==4 goto first 
if not %first%==5 goto first 
+0

非常感谢!我会记住不要在数字中使用值! – Woops