Concatenate variable name?
Posted: Mon Jan 24, 2022 3:16 pm
Very new to this, so I hope I'm explaining myself well.
I'm creating a Picross game in love2d. I have the different puzzles saved in arrays. For example...
When the player completes a puzzle I want the next puzzle to become the current puzzle. Something like...
currentPuzzle.grid = puzzle2.grid
then
currentPuzzle.grid = puzzle3.grid
I think I need a way to concatenate the variable name. I have a variable called level, which gets incremented when a puzzle is completed. So I was thinking something like...
currentPuzzle.grid = (puzzle ..level.. .grid)
Obviously that syntax wouldn't work. But I'm hoping someone can help make this work.
I'm creating a Picross game in love2d. I have the different puzzles saved in arrays. For example...
Code: Select all
puzzle2 = {}
puzzle2.xClues = {11,43,231,111,121,112,211,51,11,4}
puzzle2.yClues = {5,22,111,211,42,121,111,21,111,7}
puzzle2.grid = {0,0,1,1,1,1,1,0,0,0,0,1,1,0,0,0,1,1,0,0,0,1,0,0,1,0,0,1,0,0,0,1,1,0,1,0,0,1,0,0,1,1,1,1,0,0,0,1,1,0,
0,0,1,0,0,0,1,1,0,1,0,1,0,0,0,1,0,0,0,1,1,1,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0,0,1,1,1,1,1,1,1,0}
currentPuzzle.grid = puzzle2.grid
then
currentPuzzle.grid = puzzle3.grid
I think I need a way to concatenate the variable name. I have a variable called level, which gets incremented when a puzzle is completed. So I was thinking something like...
currentPuzzle.grid = (puzzle ..level.. .grid)
Obviously that syntax wouldn't work. But I'm hoping someone can help make this work.