Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
PwnagePineapple

[OpenGlasses] Create varying number of OpenGlasses widgets?

Question

5 answers to this question

Recommended Posts

  • 0

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.
Link to post
Share on other sites
  • 0

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

Link to post
Share on other sites
  • 0

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} } )
Link to post
Share on other sites
  • 0

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()?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.