Help is needed! I would be more than happy if someone would help me out.

Hi! I’m in the developing of my new project wich is based on a little ticker function i noticed this problem: I have a little “ticker” thing that will work like this: when i click a button, the ticker should add a new png and remove the otherone. Or now remove just make it visible and turn of the old pngs. visibility. Anyhow my code is working fine except for one thing. The ticker is working and is printing the correct things. But the TR isnt changing its status.

Please help, i’ve try to solve this problem on my own, but i neewbie like me cant handle this:/ I would be more then happy if someone could help me out:)

PS: Sorry for my bad English :slight_smile:

Thanks in advance

.Philip :slight_smile:

BTW: Here is the part of my code which isnt working properly:

[lua]TR = 1

if TR == 1 then
On1.isVisible = true
On16.isVisible = false
end

if TR == 2 then
On2.isVisible = true
On1.isVisible = false
end

if TR == 3 then
On3.isVisible = true
On2.isVisible = false
end

if TR == 4 then
On4.isVisible = true
On3.isVisible = false
end

if TR == 5 then
On5.isVisible = true
On4.isVisible = false
end

if TR == 6 then
On6.isVisible = true
On5.isVisible = false
end

if TR == 7 then
On7.isVisible = true
On6.isVisible = false
end

if TR == 8 then
On8.isVisible = true
On7.isVisible = false
end

if TR == 9 then
On9.isVisible = true
On8.isVisible = false
end

if TR == 10 then
On10.isVisible = true
On9.isVisible = false
end

if TR == 11 then
On11.isVisible = true
On10.isVisible = false
end

if TR == 12 then
On12.isVisible = true
On11.isVisible = false
end

if TR == 13 then
On13.isVisible = true
On12.isVisible = false
end

if TR == 14 then
On14.isVisible = true
On13.isVisible = false
end

if TR == 15 then
On15.isVisible = true
On14.isVisible = false
end

if TR == 16 then
On16.isVisible = true
On15.isVisible = false
end

local function TRG (event)
if(event.phase == “ended”) then
print ("Changed to: ")
if TR == 0 then
TR = 1
print (“1”)
elseif
TR == 1 then
TR = 2
print(“2”)
elseif
TR == 2 then
TR = 3;
print(“3”)
elseif
TR == 3 then
TR = 4;
print(“4”)
end
end
end

SynthBase:addEventListener(“touch”, TRG)
[import]uid: 119384 topic_id: 24200 reply_id: 324200[/import]

The problem you are having is when you change the ticker number you are not referencing your visible functions again so therefore they will not change, try something like this
[lua]local TR = 1

local checkVis = function ()
if TR == 1 then
On1.isVisible = true
On16.isVisible = false

elseif TR == 2 then
On2.isVisible = true
On1.isVisible = false

elseif TR == 3 then
On3.isVisible = true
On2.isVisible = false

elseif TR == 4 then
On4.isVisible = true
On3.isVisible = false

elseif TR == 5 then
On5.isVisible = true
On4.isVisible = false

elseif TR == 6 then
On6.isVisible = true
On5.isVisible = false

elseif TR == 7 then
On7.isVisible = true
On6.isVisible = false

elseif TR == 8 then
On8.isVisible = true
On7.isVisible = false

elseif TR == 9 then
On9.isVisible = true
On8.isVisible = false

elseif TR == 10 then
On10.isVisible = true
On9.isVisible = false

elseif TR == 11 then
On11.isVisible = true
On10.isVisible = false

elseif TR == 12 then
On12.isVisible = true
On11.isVisible = false

elseif TR == 13 then
On13.isVisible = true
On12.isVisible = false

elseif TR == 14 then
On14.isVisible = true
On13.isVisible = false

elseif TR == 15 then
On15.isVisible = true
On14.isVisible = false

elseif TR == 16 then
On16.isVisible = true
On15.isVisible = false
end
end

local TRG = function ()
TR = TR + 1
if TR == 17 then
TR = 1
end
print (TR)
checkVis()
end
SynthBase:addEventListener(“tap”, TRG)[/lua] [import]uid: 126161 topic_id: 24200 reply_id: 97688[/import]

Thank you! The code works like a charm :wink:
But if i want to connect the code to a timer, so the code is triggerd every (?) second. Do you know how to do that:)?

Thanks in advance!
//Philip :slight_smile: [import]uid: 119384 topic_id: 24200 reply_id: 97698[/import]

It depends on exactly what you mean, if you want to flip through all of the pictures then it would be very easy. just replace
[lua] SynthBase:addEventListener(“tap”, TRG)[/lua]
with
[lua] timer.performWithDelay(1000, TRG, -1)
–timer.performWithDelay(delay(in MS), function, iterations (-1 for infinite)[/lua]

that will run the function and change the picture every 1 second, increase the 1000 to increase the time between changes. [import]uid: 126161 topic_id: 24200 reply_id: 97699[/import]

Heres a different take on the code, which puts the pictures into a zero-based array so that we can use the MODULO function to increment and restart TR

(code typed free hand… hope theres no mistakes…)

local TR = 0  
--create an array of pointers to the visible objects  
local items = {}  
items[0] = On1  
items[1] = On2  
items[2] = On3  
items[3] = On4  
items[4] = On5  
items[5] = On6  
items[6] = On7  
items[7] = On8  
items[8] = On9  
items[9] = On10  
items[10] = On11  
items[11] = On12  
items[12] = On13  
items[13] = On14  
items[14] = On15  
items[15] = On16  
  
   
local function checkVis(which)   
if which ==0 then --special case if we have reached 0 again  
 items[15].isVisible = false  
 items[0].isVisible = true  
else  
 items[which].isVisible = true  
 items[which-1].isVisible = false  
end  
   
end  
   
local TRG = function ()  
   TR = TR + 1  
   TR = TR % 16 --if we pass 15, start again at 0  
   checkVis(TR)  
end  
  
SynthBase:addEventListener("tap", TRG)  

Not sure about the timer off hand. [import]uid: 108660 topic_id: 24200 reply_id: 97701[/import]

Thanks a lot guys !:slight_smile:
I dont know if you have figured out that I’m building a drummachine :slight_smile: Anyhow, I have a lot of images(dots) and if i click on of the dots its changes image to a bigger dot.
What i want is: When the “TR” is on 1 and my bigger dot is displayed then the app plays a drumsound.
Like the Drummachine in FL Studio.
(http://www.youtube.com/watch?v=a6Nmr7j52fs&feature=related).

I have the code for making the dot bigger. And i got the timer code(im using the code that 3 Dreams gaming posted). But i dont know how to combind them. So the sound is only playing if the dot is big.

I hope you understand me, otherwise just tell me and i will try to reform my description.

Thanks in Advance :slight_smile:

//Philip

Here is my code:

[lua] local function Player (event)
if(event.phase == “ended”) then
if TRB_One.isVisible == true then
ON1C.isVisible = true
TRB_One.isVisible = false;
else
ON1C.isVisible = false
TRB_One.isVisible = true;
end
end
end

TRB_One:addEventListener (“touch”, Player)
ON1C:addEventListener (“touch”, Player) [import]uid: 119384 topic_id: 24200 reply_id: 97935[/import]

Can’t somebody help me:/? I would be very happy if someone would help me:) [import]uid: 119384 topic_id: 24200 reply_id: 98508[/import]

It would be easy to play the sound when the circle is big.

first you would need to load the sound, this can be done at any point before you try to play it
[lua]local drum1Sound = audio.loadSound (“drumSound1.wav”)[/lua]

then you would need to play the sound. If i use the function that you supplied and i assume that TRB1 is the big circle then i would play the sound within the function where the big drum is visible.
[lua] local drum1Sound = audio.loadSound (“drumSound1.wav”)

local function Player (event)
if(event.phase == “ended”) then
if TRB_One.isVisible == true then
ON1C.isVisible = true
TRB_One.isVisible = false;
else
ON1C.isVisible = false
TRB_One.isVisible = true;
audio.play (drum1Sound)
end
end
end

TRB_One:addEventListener (“touch”, Player)
ON1C:addEventListener (“touch”, Player)[/lua]

hope this helps! [import]uid: 126161 topic_id: 24200 reply_id: 98644[/import]

Ok i read your post again and i think that my last post might not have been helpful for what you need. Could you explain in a little more detail, what you want to accomplish if my last post didnt help. [import]uid: 126161 topic_id: 24200 reply_id: 98647[/import]