问题描述
首先,我读了其他人的问题,这是相似的,但没有给出解决方案的合作。这也是我的第一个批处理文件之一。其背后的想法是,我preSS研究[D]将块X向右移动,和[A],将其向左。下面是该脚本。
First off, I read everybody else's questions that were similar, but none of the given solutions worked. This is also one of my first batch files. The idea behind it is that I press [D] to move the block X to the right, and [A] to move it left. Here is the script.
@echo off
:start
set z=%q%
if "%z%"=="" set z=5
choice /c ad
set x=%errorlevel%
if %x%==a goto a
if %x%==d goto b
:sett
set /a q="%z% %y% 1"
if %q%==1 goto 1
if %q%==2 goto 2
if %q%==3 goto 3
if %q%==4 goto 4
if %q%==5 goto 5
if %q%==6 goto 6
if %q%==7 goto 7
if %q%==8 goto 8
if %q%==9 goto 9
if %q%==10 set q=1 && goto 1
pause
:a
set y="-"
goto sett
:b
set y="+"
goto sett
:1
echo.X
goto start
:2
echo..X
goto start
:3
echo...X
goto start
:4
echo....X
goto start
:5
echo.....X
goto start
:6
echo......X
goto start
:7
echo.......X
goto start
:8
echo........X
goto start
:9
echo.........X
goto start
我觉得(从其他人的帖子聚集),这个问题是不是在
I think (gathered from other people's posts), that the problem is either in the
set /a q="%z% %y% 1"
或
set y="-"
或
set y="+"
我知道有可能是更容易的方式来做到这一点,但是这是我如何学习。艰辛的道路。
I know there are probably much easier ways to accomplish this, but this is how I learn. The hard way.
推荐答案
这个问题可能的组合。
语法设置VAR =串
VAR
的THA值设置为字符串
,而组VAR =串
VAR
的值设置为串
。
The syntax set "var=string"
sets tha value of var
to string
, whereas set var="string"
sets the value of var
to "string"
.
第一种形式是用于确保线路上的任何后续空格的不可以包含指定的值。第二类包括分配中的价值的报价。
The first form is used to ensure that any trailing spaces on the line are not included the value assigned. The second includes quotes in the value assigned.
因此你的设置/ A Q ...
命令将被解析为
hence your set /a q...
command would be resolved to
设置/ A Q =10+1
set /a q="5 "+" 1"
的解决方案是使用
set "y=+"
和
set /a q=%z% %y% 1
这篇关于批处理操作符丢失脚本失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!