touch the monkey

Hello, I am working on my first app called “touch the monkey” All it is a magic eight ball with a monkey. However i took out the shake event of the eight ball and put in my own touch event for the monkey. So you ask an important question, touch the monkey, and a yes, no, or maybe will pop up on screen. So I cant get it to work

local w = display.contentWidth

local h = display.contentHeight

monkey = display.newImage(“monkey.png”)

monkey.x = w/2

monkey.y = h/2
local textfield = display.newText("",w/2-5, h/2 + 40, nil, 24)

local options = {“Yes”, “No”, “Maybe”}

local function touchmonkey (e)

if (“e.phase”== ended) then

textfield.text = options[math.random(1,3)]

end

end

monkey:addEventListener(“touch”, touchmonkey) [import]uid: 75779 topic_id: 14738 reply_id: 314738[/import]

Hey there;

Change
[lua]if (“e.phase”== ended) then[/lua]
to
[lua]if (e.phase == “ended”) then[/lua]

Also, please read the forum rules - when you don’t post code in < lua > tags it’s a real pain to read.

Peach :slight_smile: [import]uid: 52491 topic_id: 14738 reply_id: 54521[/import]

Thanks Peach, what would be a good way to make the text disappear after about 5 seconds? [import]uid: 75779 topic_id: 14738 reply_id: 54555[/import]

you could do it one of the following ways :

  
transition.to(myText, {alpha = 0, delay = 500})  
  
--or  
  
local function hideText(text, iTime)  
 local function hideIt()  
 text.alpha = 0  
 end  
  
 local tmr = timer.performWithDelay(iTime, hideIt)  
end  
  
--When you want to hide the text call this  
hideText(myText, 500)   
--The text will hide after the time you specify  

hope that helps! [import]uid: 84637 topic_id: 14738 reply_id: 54617[/import]

Thanks Danny, I went with option A, I inserted it into the function and it worked.However, now i cant ask multiple questions without restarting the app. Is their a way I can do that still using option A? [import]uid: 75779 topic_id: 14738 reply_id: 54675[/import]

Never mind i figured it out. I had to put in a myText.alpha = 1 before the ‘transition.to’ line. I thought the computer would know the alpha was 1. What is the logic behind that? tnx [import]uid: 75779 topic_id: 14738 reply_id: 55026[/import]