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

line 12 attempting to call nil? split isnt working for me, HELP PLZ

Started by mattcow12, 19 November 2012 - 01:51 PM
mattcow12 #1
Posted 19 November 2012 - 02:51 PM
Hello, I am having trouble with a segment of code I have constructed involving the split command, my program is in two parts a listener which output information on a screen from rednet messages here is the listener code:


Spoiler

rednet.open("back")
door = "Unknown"
result = { }
p2 = ""
lights = "Unknown"
mon = peripheral.wrap("top")
mon.clear()
mon.setTextScale(2)
repeat
local event,p1,p2,p3 = os.pullEvent()
if event=="rednet_message" then
result = split(p2, ":")
print (split(p2, ":"))
result1 = result
result2 = result
if result1 == "door" then door = result2
elseif result1 == "lights" then lights = result2
end
mon.setCursorPos(2,2)
mon.write("Door status: "..door)
mon.setCursorPos(2,3)
mon.write("Lights status: "..lights)
end
until event=="char" and p1=="x"

And here is the client code that sends the rednet message : the error i get is that the variable "result" is nill but split should set it?

Spoiler


rednet.open("back")
redstone.setOutput("back", false)
sleep(5)
rednet.send(4, "door : open")
redstone.setOutput("back", true)
rednet.close("back")
Kingdaro #2
Posted 19 November 2012 - 03:08 PM
Don't think the function split() exists. At least in your situation. Where is this split() coming from?
mattcow12 #3
Posted 20 November 2012 - 04:39 AM
I saw it on a couple of forums…..

got any alternatives?
huettner94 #4
Posted 20 November 2012 - 05:41 AM
result is an Array. So you need:

result1 = result[0]
result2 = result[1]
TheVarmari #5
Posted 20 November 2012 - 05:53 AM
Don't think the function split() exists. At least in your situation. Where is this split() coming from?

http://lua-users.org/wiki/SplitJoin
Kingdaro #6
Posted 20 November 2012 - 06:21 AM
The problem here is that he hasn't imported/loaded/run any kind of script or API that has a split function. That's where the "attempt to call nil" is coming from.

Split isn't a default lua function.
mattcow12 #7
Posted 21 November 2012 - 06:20 AM
result is an Array. So you need:

result1 = result[0]
result2 = result[1]
nope you dont need to convert it out because the array is a string.

Don't think the function split() exists. At least in your situation. Where is this split() coming from?

http://lua-users.org/wiki/SplitJoin
yep.
mattcow12 #8
Posted 21 November 2012 - 06:23 AM
got any alternatives?