Jump to content




Need to stop concatenate from happening.


  • You cannot reply to this topic
5 replies to this topic

#1 guesswhat123212

  • Members
  • 31 posts

Posted 24 June 2014 - 01:38 AM

as I was writing a new turtle program I also decided to write a helper for sending rednet messages. I use the command sendMsg(id,reply,data1,data2,data3,data4,data5,data6) (line 121) it turns all that and then a bit more into a table and then sends the table over standard rednet.

however I am hitting a snag, I am trying to put string "co" in data1 area but then its trying to concatenate and failing.(at least that's what I am thinking its doing)

I came to this conclusion after just getting error "textutils:177: attempt to concatenate string and nil" so I added print numbers to watch where it was failing. its failing after print("11") which would be line 197.

any ideas on how to stop it from concat or is it something I am not seeing?

pastebin link to full code, http://pastebin.com/NJJuvzHZ
code snippets though they do not like my formatting.
Spoiler


#2 AssossaGPB

  • Members
  • 126 posts
  • LocationFlorida, USA

Posted 24 June 2014 - 02:19 AM

Your problem is that you forgot the quotes around "co". Also, you are calling getMsg() before it is declared, in lua any functions you call must be declared above where it is called, I know it weird.

#3 guesswhat123212

  • Members
  • 31 posts

Posted 24 June 2014 - 02:38 AM

I tried it with quotes as well which is why I removed them. However I re-added the quotes and moved getMsg() higher up and it still gives me same issue.

note: also moved transmitData(data) up as well just to make sure I was not hitting that issue. going over the rest of it now just to rule it out.

Edited by guesswhat123212, 24 June 2014 - 02:40 AM.


#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 24 June 2014 - 03:22 AM

Looking inside the textutils API, the line which is erroring out is part of the textutils.unserialize() function.

You call that in a few places, but the relevant spot seems to be here in getMsg() (called by transmitData(), which is called by sendMsg(), which is called by line 197 - next time use more print statements!):

function getMsg()
        if dataTable["wireless"] then
                recTable = {}
                sid, msg, d = rednet.receive(3)
                recTable = textutils.unserialize(msg)
        end
end

You've got a three second time out on that rednet.receive() call. If it doesn't get a reply in that time, it'll give up, and sid / msg / d each get set to nil. Attempting to unserialise msg while it's set to nil will crash out your script.

View PostAssossaGPB, on 24 June 2014 - 02:19 AM, said:

Also, you are calling getMsg() before it is declared, in lua any functions you call must be declared above where it is called, I know it weird.

This is not the case if the functions aren't localised. That's not to say that globalising them is a good idea, mind you.

Edited by Bomb Bloke, 24 June 2014 - 03:23 AM.


#5 guesswhat123212

  • Members
  • 31 posts

Posted 24 June 2014 - 03:41 AM

you sir, are awesome, i did not even think about it not getting a reply and then crashing the whole thing because of serialize (even tho its trying to find out if there is another computer to talk to). I will add a check in there for that. as for the print statements I just started adding them as I typed 98% of this while at work in notepad++. I need most (if not all) of my functions to be global because from within this code there are 8 other codes that it can run and it uses some of the functions (tracking its coords in the big one, along with the rednet)

#6 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 24 June 2014 - 04:44 AM

Unless you want the functions to be called from an entirely different script, there's never any need to globalise anything.

Even if it's not possible to order your functions such that you can localise them in the usual way (which in itself may be a sign of unwanted recursion - watch out for infinite loops!), you could always use forward declarations.

In this case, that'd be done by sticking a line up the top of the script along these lines:

local getMsg, transmitData, sendMsg, <etc>






2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users