-
os.pullEvent = os.pullEventRaw -
rednet.open("top") -
function lancp() -
term.clear -
term.setCursorPos(1,1) -
x = read() -
if -
x == 1 -
then -
rednet.broadcast("1") -
end -
if -
x == 2 -
then -
rednet.broadcast("2") -
end -
if -
x == 3 -
then -
rednet.broadcast("3") -
end -
if -
x == 999666 -
then -
rednet.broadcast("999666") -
end -
end -
repeat lancp() until x == nobodywillguessthisvalue
0
4 replies to this topic
#1
Posted 30 April 2015 - 03:41 PM
Hello, I would like to ask for help with my code, I am a beginner at Computercraft and have a problem with this code, whenever I run it it gives me an error
#2
Posted 30 April 2015 - 06:48 PM
What error does this program give to you?
Please post something like
(Second without the space at the end.)
Please post something like
error: bios:367: [string "yesthatsastring"]:123: '<name>' expectedAlso, please, please use [code] and [/code ]
(Second without the space at the end.)
Edited by Square789, 30 April 2015 - 07:01 PM.
#3
Posted 30 April 2015 - 07:08 PM
term.clear()
you don't need a channel to broadcast
channels only go to 65536
Don't put numbers in strings:
"1" ==> string
1 ==> number
x = tonumber(read())
you don't need a channel to broadcast
channels only go to 65536
Don't put numbers in strings:
"1" ==> string
1 ==> number
x = tonumber(read())
#4
Posted 30 April 2015 - 10:56 PM
Here is your code, formatted correctly and in code tags (like Square showed)
Remember to indent (With 2 spaces is the general rule in Computer Craft)
Instead of a ton of if statements, use elseif:
Now, in this specific case, you could just do this:
Like Creator said, numbers are different than Strings.
None of your if statements will ever be true, since read() always returns stuff in a string
Remember to indent (With 2 spaces is the general rule in Computer Craft)
os.pullEvent = os.pullEventRaw rednet.open("top") function lancp() term.clear --# This is probably your error - You need () term.setCursorPos(1,1) x = read() if x == 1 then rednet.broadcast("1") end if x == 2 then rednet.broadcast("2") end if x == 3 then rednet.broadcast("3") end if x == 999666 then rednet.broadcast("999666") end end repeat lancp() until x == nobodywillguessthisvalue(NOTE: The forum sometimes messes up tabs/spaces)
Instead of a ton of if statements, use elseif:
if value then elseif value2 then elseif value3 then end
Now, in this specific case, you could just do this:
x = read() rednet.broadcast(x)If you only want to do it for the values in your code then you would need to use a table
Like Creator said, numbers are different than Strings.
None of your if statements will ever be true, since read() always returns stuff in a string
x = tonumber(read()) --# Convert the value returned by 'read()' to a number
#5
Posted 01 May 2015 - 06:46 AM
Ok, thank you very much for the advice and help.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users