←  Wiki Discussion

ComputerCraft | Programmable Computers for Minecraft

»

There a way I can contribute on the wiki?...

FredMastro's Photo FredMastro 10 Mar 2014

Being new to ComputerCraft I'm going through the tutorials and will probably find issues with outdated code.

Example on the GPI API's tutorial page for Vectors it has this:

print("I am ", displacement.tostring(), " away from home!!!")

Which doesn't work. Through trial and error and going through form posts I found it works like this:

print("I am "..tostring(displacement).." away from home!!!")

I was going to update the wiki but doesn't seem I have access too. I think someone should update it though. Would have saved me research time.
Quote

Lyqyd's Photo Lyqyd 10 Mar 2014

Moved to Wiki Discussion.
Quote

Cranium's Photo Cranium 10 Mar 2014

And corrected for you. We should have people adding editors to the wiki, but I haven't been in the loop for a while.
Quote

theoriginalbit's Photo theoriginalbit 11 Mar 2014

View PostFredMastro, on 10 March 2014 - 02:25 PM, said:

I found it works like this:
print("I am "..tostring(displacement).." away from home!!!")
Cranium has already updated the wiki to an adaption of your code, but to just expand on what the problem actually was. It was because they used displacement.tostring instead of displacement:tostring since the Vector API was implemented correctly however it does implement the __tostring metamethod, meaning the 3 ways you can invoke it are as follows:
print("I am ", displacement.tostring(displacement), " away from home!!!") --# you must pass the reference to itself when using dot notation
print("I am ", displacement:tostring(), " away from home!!!") --# colon syntax makes the above easier as it automatically passes the reference
print("I am ", tostring(displacement), " away from home!!!")
basically what I'm saying here is with the print function you can pass it multiple arguments and they'll be concatenated, you don't need to concat them to print.
Quote