Problem: I can't touch the "orbs"!!!

Hello!!

When I was imitating what’s the developer coding in this video
http://goo.gl/U7U7T
I faced a problem , which is that I can’t touch the “orbs”, because
the ready constant is = false.

this is the code if you can help me !!

[code]–constants
_H = display.contentHeight;
_W = display.contentWidth;
mRand = math.random;
o = 0;
time_remain = 10;
time_up = false;
total_orbs = 20;
ready = false;

–Prepare sounds to be played or accessed
local beepSound = audio.loadSound(“media/beep.wav”);
local winSound = audio.loadSound(“media/TaDa.mp3”);
local failSound = audio.loadSound(“media/whistling.mp3”);

local display_txt = display.newText(“Wait”,0,0,native.systemFont, 16*2);
display_txt.xScale = 0.5; display_txt.yScale = 0.5;
display_txt:setReferencePoint(display.BottomLeftReferencePoint);
display_txt.x = 20; display_txt.y = _H-20;

local countdowntxt = display.newText(time_remain, 0 , 0 , native.systemFont, 16*2)
countdowntxt.xScale = 0.5; countdowntxt.yScale = 0.5;
countdowntxt:setReferencePoint(display.BottomRightReferencePoint);
countdowntxt.x = _W-20; countdowntxt.y = _H-20;
–Defining the track0rbs
local function track0rbs(obj)
obj:removeSelf();

end

local function countDown(e)

if(time_remain == 10) then
ready = true;
end
time_remain = time_remain-1;
countdowntxt.text = time_remain;

end

local function spawn0rb()
local orb = display.newImageRect(“images/sphere-omar.png” , 65 , 65);
orb:setReferencePoint(display.CenterReferencePoint);
orb.x = mRand(50 , _W-50); orb.y = mRand(50 , _H-70);
if(ready == true)then

function orb:touch(e)
if(e.phase == “ended”)then
–Play the beep sound
audio.play(beepSound);
–Remove the orbs
track0rbs(self);
end

return true;
end
end

–Increment o for every orb created
o = o+1;

orb:addEventListener(“touch” , orb);

–If all orbs created, start the game timer
if(o == total_orbs)then
gametmr = timer.performWithDelay(1000 , countDown , 10);

end

end

tmr = timer.performWithDelay(20 , spawn0rb , total_orbs);
[/code]

*sorry for my bad English, because the English is not my first language.

*I’m sure that I do everything that was in the video. [import]uid: 133838 topic_id: 24164 reply_id: 324164[/import]

Hi wa7dawy.96

According to the video, the ready = true at line 47, needs to be moved from the local function spawn0rb()to the function orb:touch(e) below.

Here is the code, which is working:

[lua] --constants
_H = display.contentHeight;
_W = display.contentWidth;
mRand = math.random;
o = 0;
time_remain = 10;
time_up = false;
total_orbs = 20;
ready = false;

–Prepare sounds to be played or accessed
local beepSound = audio.loadSound(“media/beep.wav”);
local winSound = audio.loadSound(“media/TaDa.mp3”);
local failSound = audio.loadSound(“media/whistling.mp3”);

local display_txt = display.newText(“Wait”,0,0,native.systemFont, 16*2);
display_txt.xScale = 0.5; display_txt.yScale = 0.5;
display_txt:setReferencePoint(display.BottomLeftReferencePoint);
display_txt.x = 20; display_txt.y = _H-20;

local countdowntxt = display.newText(time_remain, 0 , 0 , native.systemFont, 16*2)
countdowntxt.xScale = 0.5; countdowntxt.yScale = 0.5;
countdowntxt:setReferencePoint(display.BottomRightReferencePoint);
countdowntxt.x = _W-20; countdowntxt.y = _H-20;

–Defining the track0rbs
local function track0rbs(obj)
obj:removeSelf();

end

local function countDown(e)

if(time_remain == 10) then
ready = true;
end
time_remain = time_remain-1;
countdowntxt.text = time_remain;

end

local function spawn0rb()
local orb = display.newImageRect(“images/sphere-omar.png” , 65 , 65);
orb:setReferencePoint(display.CenterReferencePoint);
orb.x = mRand(50 , _W-50); orb.y = mRand(50 , _H-70);

function orb:touch(e)
if(ready == true)then
if(e.phase == “ended”)then

–Remove the orbs
track0rbs(self);
end

return true;
end
end

–Increment o for every orb created
o = o+1;

orb:addEventListener(“touch” , orb);

–If all orbs created, start the game timer
if(o == total_orbs)then
gametmr = timer.performWithDelay(1000 , countDown , 10);

end

end

tmr = timer.performWithDelay(20 , spawn0rb , total_orbs)[/lua]

I hope it helps :slight_smile: [import]uid: 122802 topic_id: 24164 reply_id: 97551[/import]

thank you for your effort :slight_smile: , but it doesn’t work , because the purpose is to make the orbs non-touchable when the time remain = 0

but it became non-touchable all the time !!

I will watch the video again :slight_smile: [import]uid: 133838 topic_id: 24164 reply_id: 97567[/import]

Hello

Umm, to do make the orbs untouchable when the time is zero, you need to do three things I think.

First:
add this to the countDown function.

 if(time\_remain == 0) then  
 time\_up = true  
 end  

Secondly:
your orb:touch function needs an added bit
[lua]function orb:touch(e)
if (ready == true) then
–you need to have this bit :slight_smile:
if (time_up ~= true) then
if (e.phase == “ended”) then
–remove orb
trackOrbs(self)
end
end
end
return true

end[/lua]

Thirdly(and lastly I think):
you need to have this bit of code.
[lua] if(o == total_orbs) then
gametmr = timer.performWithDelay(1, countDown, 10)
else
ready = false
end
end[/lua]

Please let me know if this has helped or if you need more help :slight_smile:

Also take a look at my game with this tutorial :wink: http://bit.ly/H6KgAK [import]uid: 67534 topic_id: 24164 reply_id: 97592[/import]

Thanks for everyone :slight_smile: … I was hasty when I ask the question … but when I watch the video to the end … I found my mistake! [import]uid: 133838 topic_id: 24164 reply_id: 97660[/import]

I’m glad you solved it! [import]uid: 67534 topic_id: 24164 reply_id: 97664[/import]