0

I have a 2d array of objects, the objects contain a text object and a boolean parameter called "hold". I'd like to be able to change the text colour and change the hold paramater when you click on the text. At the moment I have a tap eventlistener on all the text objects and I can change the colour no problem using the event.target, but how would I be able to change the "hold" parameter which is a sibling of the text object? is there anything like event.target.parent???

heres the pertinent code...

    --CONSTRUCTOR in dice.lua

    function dice.new(x, y) 

    local newdice = {hold = false, dicetext = display.newText(math.random(1,6), 50*x , 50*y , nil, 50)} 

    return setmetatable(newdice, dice_mt) 
    end


            --2d array (this and the rest of the code is from main.lua)


    mainarray = {}

    for x = 1, 5, 1 do
    mainarray[x] = {}

    for y = 1, 5, 1 do
    mainarray[x][y] = diceclass.new(x,y)

    end
    end


            --add event listeners to text

    for x = 1, 5, 1 do
    for y = 1, 5, 1 do
    mainarray[x][y].dicetext:addEventListener("tap", bloop)
    end
    end


            --function that is called

    function bloop(event)
    print("bloop")
    print(event.target)
    event.target:setTextColor(255,0,0)
    end

1 Answer 1

0

ok, I just added a hold parameter to the text object itself! That did the trick!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.