Jump to content

Combining strings? AKA: Concatenation

Recommended Posts

Here's what I know so far: https://www.lua.org/pil/3.4.html

Thing is, it doesn't seem to work at all the way I'm using it.  Is it even possible?

local a = Testing
STRINGS.CHARACTER_DESCRIPTIONS.furryeskimo = (a .. "Testing")  --Expected outcome: "Testing Testing"

Edit:  Figured it out.  Pretty basic actually, and I'm mostly leaving this here so others know.  This game me a clue: 


local a = "Testing"  --THIS needs to be in quotes, which seems obvious, but it can be easy to overlook.
STRINGS.CHARACTER_DESCRIPTIONS.furryeskimo = a .. "Testing"  --Expected outcome: "Testing Testing"

>>>I'm using this to make a custom character description, changing based on the mod's configuration settings.

Link to comment
Share on other sites

@FurryEskimo It doesn't work because a isn't a string. It's nil.

-- Bad --------------------------------------

local a = Testing -- Testing here is a nil variable. This will not work for concatenation.
print(a .. "Testing") -- This will error because a is nil.

-- Good ------------------------------------

local a = "Testing" -- This is a string, which is required for concatentation.
print(a .. " Testing") -- This will print "Testing Testing"

-- So your revised code is...
local a = "Testing"
STRINGS.CHARACTER_DESCRIPTIONS.furryeskimo = a .. " Testing"


Edited by penguin0616
syntax highlighting problem?
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...