循环和嵌套 if 语句的问题
Issue with loop and nested if statements
motor = peripheral.wrap("right")
repeat
RPM = motor.getSpeed()
print("current rpm is ", RPM, "RPM. What RPM do you need?")
setrpm = tonumber(io.read())
if type(setrpm) == "number"
then
motor.setSpeed(setrpm)
goto contine
else
print("Must be a number between -256 and 256")
print("current rpm is ", RPM, "RPM. What RPM do you need?")
setrpm = tonumber(io.read())
end
::continue::
rpm = motor.getSpeed()
su = ( rpm * 16)
fe = motor.getEnergyConsumption()
print("You have set speed " , rpm, " RPM")
print("Current stress cap is now ", su, "SU")
print("Power Consumption is now ", fe, "FE/t")
until( fe > 100 )
end
预期行为
循环直到 fe=100 或更多
当前行为
motor.lua:12 '=' 预计在 'continue'
附近
在 computercraft 中编写一个代码循环来询问一个块需要以什么 rpm 旋转,预期的行为是不断循环代码直到 FE>100(对于它看起来不可能的块)
Computercraft 使用 Lua 5.1。 goto
是在 Lua 5.2 中引入的,因此您不能在脚本中使用它。
除此之外,那样使用它没有任何意义。
if condition then
-- block A
else
-- block B
end
执行块A或B后Lua会在end
后自动继续。
您不必明确告诉 Lua 这样做。
在 repeat until 语句中,条件后没有 end
。正确的语法是:
repeat block until exp
在此处发布您的问题之前,至少检查一下是否有拼写错误。 contine
不是您要访问的标签。
motor = peripheral.wrap("right")
repeat
RPM = motor.getSpeed()
print("current rpm is ", RPM, "RPM. What RPM do you need?")
setrpm = tonumber(io.read())
if type(setrpm) == "number"
then
motor.setSpeed(setrpm)
goto contine
else
print("Must be a number between -256 and 256")
print("current rpm is ", RPM, "RPM. What RPM do you need?")
setrpm = tonumber(io.read())
end
::continue::
rpm = motor.getSpeed()
su = ( rpm * 16)
fe = motor.getEnergyConsumption()
print("You have set speed " , rpm, " RPM")
print("Current stress cap is now ", su, "SU")
print("Power Consumption is now ", fe, "FE/t")
until( fe > 100 )
end
预期行为 循环直到 fe=100 或更多
当前行为 motor.lua:12 '=' 预计在 'continue'
附近在 computercraft 中编写一个代码循环来询问一个块需要以什么 rpm 旋转,预期的行为是不断循环代码直到 FE>100(对于它看起来不可能的块)
Computercraft 使用 Lua 5.1。 goto
是在 Lua 5.2 中引入的,因此您不能在脚本中使用它。
除此之外,那样使用它没有任何意义。
if condition then
-- block A
else
-- block B
end
执行块A或B后Lua会在end
后自动继续。
您不必明确告诉 Lua 这样做。
在 repeat until 语句中,条件后没有 end
。正确的语法是:
repeat block until exp
在此处发布您的问题之前,至少检查一下是否有拼写错误。 contine
不是您要访问的标签。