0
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

Expected behavor loop until fe=100 or more

current behavor motor.lua:12 '=' expected near 'continue'

writing a loop of code in computercraft to ask what rpm a block needs to spin at, expected behavor is to keep looping the code endlessly till the FE>100 (for the block its looking at its imposible)

2
  • 1
    you have an extra end, and you typoed continue in the goto statement, also most importantly that goto does absolutely nothing and using goto in general is a code smell. Commented Nov 2, 2021 at 19:17
  • 1
    It looks like you are using Lua 5.1, there is no goto operator in this Lua version. Commented Nov 2, 2021 at 19:21

1 Answer 1

1

Computercraft uses Lua 5.1. goto was introduced in Lua 5.2 so you cannot use it in your script.

That aside there is no point in using it like that.

if condition then
  -- block A
else
  -- block B
end

After executing block A or B Lua will automatically continue after the end. You don't have to explicitly tell Lua to do that.

In a repeat until statement there is no end after the condition. The correct syntax is:

repeat block until exp

Befor posting your problems here, at least check for typos. contine is not the label you intended to go to.

Please refer to https://www.lua.org/manual/5.1/manual.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.