PwnagePineapple 0 Posted June 26, 2016 Share Posted June 26, 2016 How might one go about creating a varying number of OpenGlasses widgets in a single block of code? Quote Link to post Share on other sites
0 Solution PwnagePineapple 0 Posted June 27, 2016 Author Solution Share Posted June 27, 2016 Never mind, I can just make each widget an index in a table using table.insert() Quote Link to post Share on other sites
0 Lizzian 46 Posted June 26, 2016 Share Posted June 26, 2016 You could use a table and then store them in that. So like: local shapes = {} function CreateSquares() shapes.SquareA = glasses.createSquare() ... end Obviously replacing bits with the actual code, I haven't dabbled much with Open Glasses so don't know it's functions. Quote Link to post Share on other sites
0 PwnagePineapple 0 Posted June 26, 2016 Author Share Posted June 26, 2016 You could use a table and then store them in that. So like: local shapes = {} function CreateSquares() shapes.SquareA = glasses.createSquare() ... end Obviously replacing bits with the actual code, I haven't dabbled much with Open Glasses so don't know it's functions. The problem with that, is that requires me to have squareA, squareB, and squareC already in existence, all the way to SquareN. I would like a theoretically infinite amount of widgets, and you're solution doesn't allow for that. BTW the OpenGlasses documentation can be found here: http://og.starchasers.pl/doku.php Quote Link to post Share on other sites
0 Lizzian 46 Posted June 26, 2016 Share Posted June 26, 2016 The problem with that, is that requires me to have squareA, squareB, and squareC already in existence, all the way to SquareN. I would like a theoretically infinite amount of widgets, and you're solution doesn't allow for that. BTW the OpenGlasses documentation can be found here: http://og.starchasers.pl/doku.php If you're not worried about addressing individual squares (or at least, not easily), you could try: local Shapes = {} function CreateSquares( Values ) -- Where values is a table like so: { {x=2,y=2,w=3,h=3}, {x=3,y=4,w=5,h=2} } for i,v in pairs( Values ) do -- iterates over the table, so the first iteration: i would be 1 and v would be {x=2,y=2,w=3,h=3} local sq = glasses.addRect() sq.setPosition( v.x, v.y ) -- these reference the x&y variables in the table sq.setSize( v.w, v.h ) table.insert( Shapes, sq ) end end -- then call it like so. CreateSquares( { {x=2,y=2,w=3,h=3}, {x=3,y=4,w=5,h=2} } ) Quote Link to post Share on other sites
0 PwnagePineapple 0 Posted June 26, 2016 Author Share Posted June 26, 2016 If you're not worried about addressing individual squares (or at least, not easily), you could try: local Shapes = {} function CreateSquares( Values ) -- Where values is a table like so: { {x=2,y=2,w=3,h=3}, {x=3,y=4,w=5,h=2} } for i,v in pairs( Values ) do -- iterates over the table, so the first iteration: i would be 1 and v would be {x=2,y=2,w=3,h=3} local sq = glasses.addRect() sq.setPosition( v.x, v.y ) -- these reference the x&y variables in the table sq.setSize( v.w, v.h ) table.insert( Shapes, sq ) end end -- then call it like so. CreateSquares( { {x=2,y=2,w=3,h=3}, {x=3,y=4,w=5,h=2} } ) So if I did have to address them (for the purpose of removing them later) I would iterate over the shapes table and delete them all using glasses.removeObject()? Quote Link to post Share on other sites
How might one go about creating a varying number of OpenGlasses widgets in a single block of code?
Link to post
Share on other sites