Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Adding identifier to rect object

edited May 2012 in Questions Posts: 2


I'm trying to build a simple puzzle-like app. I basically have some letters (the pieces) and some receiving boxes. The pieces are stored in an array {Id, letter} their receiving boxes are stored in another array {Id, letterId, xCoordinate}. yCoordinate, width, height and distance between the objects are constant for all receiving boxes.

What I'm trying to accomplish is a match between the letters and their receiving box by giving each letter an identifier that can be matched against the letterId in the receiver array. But how to add this identifier to the letter string/rect/whatever object?

I'm not sure if this is the best way to do this, so other suggestions are welcome :)



  • Posts: 1,255

    The easiest way is to create a class. For example:

    Box = class()
    function Box:init(left, bottom, right, top, letter)
        self.left = left
        self.right = right
        self.bottom = bottom = top
        Self.letter = letter
    function Box:draw()
        rect(self.left, self.bottom, self.right,

    Create this as a class, then in your Main store your rects as a table of Box.

    For example:

    boxes = {}
    boxes[1] = Box(100,100,200,200,"A")
    boxes[2] = Box(300,300,400,400,"B")

    And so on. Does that come close to answering the question?

  • edited May 2012 Posts: 2

    Thanks for your reply, Mark!

    I'm not entirely sure if it is what I'm after, but I'll test it a bit more. What I'm looking for is a way to identify the touched object (the puzzle piece) and compare its id to the id stored in the box to see if the piece matches the receiving box.

    Something like:

    Piece={Id, letter}
    Receiver={id, Id of expected piece}

    So that if




    I will know that piece 2 I supposed to go into reciever 1.

    Does this make sense to anyone but me?

Sign In or Register to comment.