Hey guys, so i have always had a hard time understanding the correct syntax for combining variable names and so forth.
For example i know i can do the following:
[lua]narrativeAudio = audio.loadSound(“nar”…thisStoryNumber…“p”…thisPageNumber…".mp3")[/lua]
This works out great. Now what im trying to do is figure out if its possible to “combine” (im not sure what the correct term is…) two variable names. For example here is what im currently trying.
[lua]M.createDialogHitbox = function( hitBoxPosX, hitBoxPosY, character )
–Create new hitBox object
M.charHitBox1 = ui.newButton{
defaultSrc = “blackBox.png”,
defaultX = 0,
defaultY = 0,
onEvent = charDialogue
}
M.charHitBox1.x = hitBoxPosX.character.[global.thisPageNumber]
M.charHitBox1.y = hitBoxPosY.character.[global.thisPageNumber]
end[/lua]
So I have two tables created like so…
[lua]–Hitbox positioning for characters in this story
local HitBoxPosX = { marc = 0, sam = 0}
local HitBoxPosY = { marc = 0, sam = 0}
HitBoxPosX.marc[0] = 300
HitBoxPosY.marc[0] = 0
HitBoxPosX.sam[0] = 200
HitBoxPosY.sam[0] = 0[/lua]
So the idea is that I have just the one function that I want to pass the two tables, and then the character variable will change. (could be “marc” or “sam”)
The variable “character” is currently a string and i would change it to whatever name i want before calling the function.
Hopefully this makes some sense, im sure there is a better way to handle this in general… Any ideas of the syntax for this or the better way to handle what i want to do?
Thanks [import]uid: 19620 topic_id: 26478 reply_id: 326478[/import]