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

A little help please :P

Started by Enderslime, 11 December 2015 - 07:06 PM
Enderslime #1
Posted 11 December 2015 - 08:06 PM
current = ""
linked = ""
local Buttons = {}

Buttons["2,2"] = "1"
Buttons["2,4"] = "2"
Buttons["2,6"] = "3"
Buttons["2,8"] = "4"
Buttons["2,10"] = "5"
Buttons["2,12"] = "6"
Buttons["2,14"] = "7"
Buttons["2,16"] = "8"
Buttons["2,18"] = "9"
Buttons["2,20"] = "0"
Buttons["2,22"] = "LINK"
Buttons["2,23"] = "LINK"
Buttons["2,24"] = "LINK"
Buttons["2,25"] = "LINK"
Buttons["2,1"] = "F"
Buttons["2,2"] = "F"
Buttons["3,1"] = "B"
Buttons["3,2"] = "B"
Buttons["4,1"] = "TL"
Buttons["4,2"] = "TL"
Buttons["5,1"] = "TR"
Buttons["5,2"] = "TR"
Buttons["6,1"] = "BB"
Buttons["6,2"] = "BB"


function draw()
if linked ~= "" then    
term.clear()
term.setCursorPos(2,20)
print("Linked to ID "..linked)
term.setCursorPos(1,2)
print("[] Forward")
print("[] Backward")
print("[] Turn Left")
print("[] Turn Right")
print("[] Break Block")
elseif linked == "" then
term.clear()
term.setCursorPos(2,2)
term.setTextColor(colors.blue)
print("1 2 3 4 5 6 7 8 9 0 LINK")
term.setCursorPos(1,4)
print(current)
elseif linked ~= "" and press == "F" then
rednet.send(linked,"Forward")
end
end

while true do
draw()
local event, button, x, y = os.pullEvent("mouse_click")
press = Buttons[y..","..x]
if press == "1" or press == "2" or press == "3" or press == "4" or press == "5" or press == "6" or press == "7" or press == "8" or press == "9" or press == "0" and linked == "" then
term.setCursorPos(4,4)
current = current..press
elseif press == "LINK" and current ~= "" then
linked = current 
end
end


Around the area where im testing for F it includes that area in a string, its highlighted red. I have no idea why this is happening , help I think this is the cause of my code not working, though im not entirely sure
0099 #2
Posted 11 December 2015 - 08:28 PM
The fact that that part is highlighted red is just a bug in the editor's way of processing strings, especially empty strings (like ""). This has nothing to do with the code. Concerning your code, I have 2 things to say:
1. In your multi-choice if statement the third option will never run. If linked~="" then it will execute lines 33 to 41 and exit the if statement. If linked=="" then it will execute lines 43 to 48 and exit. The variable "linked" either equals "" or it doesn't. So line 50 just won't run.
2. Why do you even send a rednet message in a function named "draw"? The point in "draw" functions is that you can call them anywhere you want any number of times and it will affect nothing but the screen. In your case, one extra "draw()" could potentially break the whole system.
Enderslime #3
Posted 11 December 2015 - 09:43 PM
The fact that that part is highlighted red is just a bug in the editor's way of processing strings, especially empty strings (like ""). This has nothing to do with the code. Concerning your code, I have 2 things to say:
1. In your multi-choice if statement the third option will never run. If linked~="" then it will execute lines 33 to 41 and exit the if statement. If linked=="" then it will execute lines 43 to 48 and exit. The variable "linked" either equals "" or it doesn't. So line 50 just won't run.
2. Why do you even send a rednet message in a function named "draw"? The point in "draw" functions is that you can call them anywhere you want any number of times and it will affect nothing but the screen. In your case, one extra "draw()" could potentially break the whole system.
draw was at the beggining a way to draw the screen, at this point its just become a function for calling anywhere in the code
0099 #4
Posted 11 December 2015 - 10:00 PM
draw was at the beggining a way to draw the screen, at this point its just become a function for calling anywhere in the code
But I was saying that if you start calling that function "anywhere in the code" then your computer will probably send way more rednet messages than it needs. I mean, it will send them if you fix the first problem, which is rednet.send never actually being called.