7 posts
Posted 19 November 2012 - 06:46 AM
If i want a computer to print 3 terms, with commas inbetween, is there an easier way than:
print("Current: ",x",",y,",",z)
not paricularly urgent, just thought i must be being inefficient :)/>/>
Thanks
2088 posts
Location
South Africa
Posted 19 November 2012 - 06:51 AM
Not that i know of. Why does it matter?
You could make the x y z into one variable, I guess?
pos = x .. " " .. y .. " " .. z
print("Current: " .. pos)
536 posts
Posted 19 November 2012 - 06:55 AM
If you really want to:
print "Current: "..x.." "..y.." "..z
will "," work?, this gets rid of one character presuming "," won't work, I think it does though…
There should be efficiency challenges on the forums, someone gives a bit of code and everyone else tries to make it as efficient as possible, the character count is what the efficiency is measured in :)/>/>
2088 posts
Location
South Africa
Posted 19 November 2012 - 07:15 AM
I started using CC with Tekkit. I had no clue you could use commas so I have stuck to double dots since :)/>/>
7 posts
Posted 19 November 2012 - 07:24 AM
okay, turning it into a single variable should help, but yeah "," does work.
and it's only a matter of lazyness :)/>/>
1054 posts
Posted 19 November 2012 - 08:12 AM
Well, if it's just a matter of using frequently in code, I suggest making a little helper function:
local function cur(x,y,z)
print( string.format("Current: %d,%d,%d", x, y, z) )
end
It still doesn't make the actual function shorter of course. It just makes it shorter to use in the code (supposing that you have to use it like 30 times or so x'D).
1688 posts
Location
'MURICA
Posted 19 November 2012 - 08:17 AM
I was going to suggest something similar to what Orwell suggested, but then I thought about something. Strings can usually have their methods acted upon them, like:this(). I tested if this works with string.format and well,
print(("Current: %d, %d, %d"):format(x, y, z))
This is apparently valid. Apparently.