Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Newbie questions, cach value from buttons and more — Gideros Forum

Newbie questions, cach value from buttons and more

SpiegelSpiegel Member
edited August 2012 in Game & application design
Hi, first of all sorry for my english U_U and for my very noob questions

I made a very simple app in android, for calculate role dices >> https://play.google.com/store/apps/details?id=com.bebop.letsroll
and now I want to make it with Gideros for in a future add effects and dice movement

this is my mockup for now in GiderosPlayer >> http://img507.imageshack.us/img507/4599/letsrolltest.png

the dice buttons are a independent buttons, and + and - are a made with hieritachy example of GiderosStudio

the question: I need a listener for each button? or can made a global that cach the value of "clicked" button?

i want to change the value "0" of each dice and calculate the result

for now i use this for each button:

d4:addEventListener("click",
function()
numtxt = "d4"
resultat = math.floor(math.random()*4)+1
label:setText("Resultat " .. numtxt .. resultat)
end)

thank you very much



Comments

  • talistalis Guru
    edited August 2012 Accepted Answer
    @Spiegel
    Here you have 2 alternatives i guess.
    1-Mouseclick event for each button.
    2-One mouse down event for the stage or for your main sprite class and do a hit test control for each of your buttons like.
    --supposing Page1 is your main class sprite
    function Page1:onMouseDown(event)
    	-- touch event begins here. you need to get the initial x and y, we will use them later
    	if (self.button1:hitTestPoint(event.x, event.y) == true) then 
    		--do on click of button1
     
    	elseif (self.button2:hitTestPoint(event.x, event.y) == true) then 
    		--do on click of button2
                    --and going on if you want to handle more buttons.
    	end
     
    end
  • petecpetec Member
    Accepted Answer
    I've used a single function to pick up on different buttons before by allocating each button a value when setting up the button objects:
    self.button1.value=4
    self.button2.value=5
    -- and so on
    then using the value in the function called by the listener, so in your case something like:
    resultat = math.random(value)
    -- which will give a random integer from 1 to value
    Hope that makes sense :)
  • thank you!
    @tails and @petec I'll work on that
Sign In or Register to comment.