This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ryarsh's profile picture

Help me please error in comp craft programming '=' expected

Started by ryarsh, 07 November 2012 - 05:10 PM
ryarsh #1
Posted 07 November 2012 - 06:10 PM
print("Loading…")
write "choose Option…"

print("Empty")
print("Power")

x = Empty
y = Power


input = read()
if x == Empty then
rs.setBundledOutput( "right!, colors.lime)

input = read()
if y == Power then
rs.setBundledOutput( "right", colors.white)
sleep(1)

else
printed("incorrect answer")
sleep(2)
os.shutdown
end


help please, the message i get is the following…. bios:206: [string "bundle] :25: '=' expected
any help is appreciated ty :P/>/>
jag #2
Posted 07 November 2012 - 06:13 PM
os.shutdown()
You missed the brackets at the end
ryarsh #3
Posted 07 November 2012 - 06:15 PM
Thanks, i owe you one :P/>/>
Kryptanyte #4
Posted 07 November 2012 - 06:20 PM
I cleaned up your code a little bit as well as fix it.



print("Loading...")
print("choose Option...")
print("Empty")
print("Power")
 
local x = Empty
local y = Power

input = read()
if input == "x" then
rs.setBundledOutput( "right", colors.lime)

elseif input == "y" then
rs.setBundledOutput( "right", colors.white)
sleep(1)

elseif input ~= "x" or "y" then
print("incorrect answer")
sleep(2)
os.shutdown()
end


The problems were that you didn't have the options in one 'if' statement. Also on os.shutdown() you forgot the (). The 2nd line also was a write command so 'Empty' was being put on the same line as choose option. Added local to your variables.

You are welcome to ask any more questions about this code.
jag #5
Posted 07 November 2012 - 06:37 PM
I cleaned up your code a little bit as well as fix it.



print("Loading...")
print("choose Option...")
print("Empty")
print("Power")

local x = Empty
local y = Power

input = read()
if input == "x" then
rs.setBundledOutput( "right", colors.lime)

elseif input == "y" then
rs.setBundledOutput( "right", colors.white)
sleep(1)

elseif input ~= "x" or "y" then
print("incorrect answer")
sleep(2)
os.shutdown()
end


The problems were that you didn't have the options in one 'if' statement. Also on os.shutdown() you forgot the (). The 2nd line also was a write command so 'Empty' was being put on the same line as choose option. Added local to your variables.

You are welcome to ask any more questions about this code.
You got it wrong, but the right idea.
You are checking if the input is equal to the string "x". Not the variable x.
And also you can't do
elseif input ~= x or y then
The easiest way is just to put in
else
But if you want to do it like that then you'll have to do
elseif input ~= x or input ~= y then
Kryptanyte #6
Posted 07 November 2012 - 06:40 PM
Yeah thats a mental failure on my part. Sorry haven't had much sleep and its not good to code when half asleep. xD Thanks for correcting my mistakes ^^