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

[Lua][Error]Trying to split String returns error

Started by jeepracer98, 19 March 2012 - 07:59 PM
jeepracer98 #1
Posted 19 March 2012 - 08:59 PM
Hello, I am building a mail server.
my code so far is:
In my program, when it runs into

sp = spllit( message, "#$" )
where #$ is what I split my id and message with,
it tells me that there is a nil value.
Am I doing something wrong?

Thanks,
JR98
Espen #2
Posted 19 March 2012 - 09:12 PM
It would help to see the actual code for your split function, but so far I'd guess you just mistyped the call to it.
You tried to call spllit, which might not exist, I guess you wanted to call split ( with one "l" ).
jeepracer98 #3
Posted 19 March 2012 - 09:32 PM
Oops, I accidentally misspelled that code because I was typing fast, sorry.
Here is the code for the Server

rednet.open("top")
while true do
event, id, message = os.pullEvent()
if event == "rednet_message" then
  print("incoming message" )
  sp = split( message, "#$" )
  msg = sp[1]
  id = tonumber(sp[0])
  print(id)
  print(msg)
end
end

The Client Software is like so, yet I don't think it has anything to do with the client program:

term.clear()
term.setCursorPos(1, 1)
print("To:")
t = io.read()
print("Body:")
b = io.read()
msg = table.concat( { t, b }, "#$" )
rednet.open("top")
rednet.send(2, msg)
rednet.close("top")
Espen #4
Posted 19 March 2012 - 09:52 PM
So where is the code for the split function?
Because if you have none, then that's at least an explanation for the error "attempt to call nil", because you can't call a function that doesn't exist (i.e. is "nil").
Lua doesn't have a native split function, you have to program your own or take one from the internet.

If that's actually the case for you, then take a look at these examples: http://lua-users.org/wiki/SplitJoin
jeepracer98 #5
Posted 19 March 2012 - 09:56 PM
So where is the code for the split function?
Because if you have none, then that's at least an explanation for the error "attempt to call nil", because you can't call a function that doesn't exist (i.e. is "nil").
Lua doesn't have a native split function, you have to program your own or take one from the internet.

If that's actually the case for you, then take a look at these examples: http://lua-users.org/wiki/SplitJoin

Oh, I did not realize that. Thanks.