16 posts
Location
Oviedo, Florida
Posted 22 May 2013 - 08:25 AM
Hey, guys.
This ought to be an easy question for a pro.
Can you concatenate a variable with a string to create a path?
Example:
zipcode = 1234
fs.open("disk/" .. zipcode, "r")
Would that work and open "disk/1234"?
1583 posts
Location
Germany
Posted 22 May 2013 - 08:32 AM
Yes that works with tostring()
local zipcode = 1234 --here is the numeric variable
local file = fs.open("disk"..tostring(zipcode), "r") --tostring converts zipcode into a string
16 posts
Location
Oviedo, Florida
Posted 22 May 2013 - 08:35 AM
Thank you very much.
1688 posts
Location
'MURICA
Posted 22 May 2013 - 12:02 PM
For the record, numbers are automatically converted to strings when concatenated.
local num = 5
local str = 'hello'
print(str .. num) --> hello5
print(num .. num) --> 55
93 posts
Posted 22 May 2013 - 09:29 PM
Your code worked when you first created it. If not, it is a bug. Like Kingdaro said, numbers are automatically "tostring'ed" if you will when concatenated.