How to a concatenate an already defined variable? for example:
local Var = HelloWorld -- not a string however
local word1 = Hello
local word2 = World
exampleFunction(word1..word2)
Or is this impossible?
How to a concatenate an already defined variable? for example:
local Var = HelloWorld -- not a string however
local word1 = Hello
local word2 = World
exampleFunction(word1..word2)
Or is this impossible?
Hey Marmalados,
#OOP Review
##A part is just an object made through a class defined.(This is called OOP, when you orient the program through objects: Object Oriented Programming) When you try to print an object that is created through the class, it tries to convert the instance to a string. In order to do this, it looks for the str method(Python), or basically the method that is supposed to return the string representation of the object.
##What Roblox did with this method is just return the name of the object. So, if you try to do something like this:
part = workspace.Part
part2 = workspace.Part2
var1 = tostring(part)
var2 = tostring(part2)
print(var1) -- Prints: Part
print(var2) -- Prints: Part2
##They just convert the part to a string, and that string is the name of the object.
#Solution
##So, as you may see above, you can get their string representation by converting them to strings. After doing so, you can easily concatenate them. Something like this:
part = workspace.Part
part2 = workspace.Part2
var1 = tostring(part)
var2 = tostring(part2)
print(var1..var2) -- Prints: PartPart2
#Conclusion
##The reason the print method works with instances is that it gets the string representation of the instance, which Roblox has put as the name of the object. You can only concatenate strings. I hope i helped and have a wonderful day.
Thanks,
Best regards,
KingLoneCat
Just for clarification, objects and instances are interchangable.
I think you might want to fix the formatting in this answer - it's a bit big.
I designed it that way... What's big? The font? Yeah, it's supposed to be organized.
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
local var = "hello"print(var .. " world")