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

Attempt To Concatenate Function And String Workaround

Started by Inumel, 28 July 2013 - 08:15 PM
Inumel #1
Posted 28 July 2013 - 10: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!
GopherAtl #2
Posted 28 July 2013 - 11: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
Inumel #3
Posted 29 July 2013 - 12:12 AM
How did I not notice that… I am such a derp sometimes :(/>
Thanks for the help, Gopher