Jump to content




Attempt To Concatenate Function And String Workaround


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

#1 Inumel

  • Members
  • 120 posts

Posted 28 July 2013 - 09:15 PM

Hello! As the title says, I am getting the error "attempt to concatenate function and string"

This is my code http://pastebin.com/kR2uD4tY

I am trying to make a small chat program for the miscperipherals smarthelmet item, just for funsies.

And I want to use the computer name as the "username", But I am getting that error when i do so.

I have also tried
message = os.getComputerLabel(), " said: " .. message
And that only gives me the username, In this case would be Elg, but not the "said" or the actual message

Any help is appreciated, Thanks!

#2 GopherAtl

  • Members
  • 888 posts

Posted 28 July 2013 - 10:58 PM

you need the () on os.getComputerLabel, which you have in the line you pasted but not in your original code. Without the (), it's just the function itself, which you can't concatenate into strings (which is what ".." does). With the (), it is the value returned by the function, which is in this case a string, and which you can concatenate.

tl;dr: message = os.getComputerLabel().." said: " .. message

#3 Inumel

  • Members
  • 120 posts

Posted 28 July 2013 - 11:12 PM

How did I not notice that... I am such a derp sometimes :(
Thanks for the help, Gopher





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users