Game works perfectly on simulator but not on actual device

Hi

Ive been working on a simple game where you controller a character who avoids water drops that drop from the sky.

For some reason, the water drop frequency is getting broken when running on an actual device (ive set it to drop every 0.25ms) - There are some periods where no drops are comming for some reason.

this is the code which handles the drops:

local function spawnWater()    -- create sample item     local waterSize = math.random( 20, 26 );     local water = display.newImageRect( "images/water.png", waterSize, waterSize \* 1.25 );     water.id = "water";     physics.addBody( water, {         isSensor = true,         filter = {             categoryBits = 16,             maskBits = 1 + 2         }     })     water.gravityScale = math.random( 0.8, 1)          -- position item randomly within set bounds     water.x = math.random( water.contentWidth, \_W - water.contentWidth );     water.y = -( water.contentHeight );     -- add item to spawnedObjects table for tracking purposes     table.insert( spawnedObjects, water ); end

Someone has any idea why such as thing could happen? thank you very much

We need to see the timer code really.

Also, math.random only accepts integers. To get a value between 0.8 and 1 do math.random(8/10)/10.

Ive changed the gravityScale’s properties but still got the same problem… 

here’s the code of the spawnController(timer):

local function spawnController( action )     if ( spawnTimer and ( action == "start" or action == "stop" ) ) then         timer.cancel( spawnTimer );     end     if( action == "start" ) then         local spawnTime = 250;         spawnTimer = timer.performWithDelay( spawnTime, function( e )             spawnWater();             if( e.count % 36 == 0 ) then             local rand = math.random( 0, 4 );         if( rand ~= 0 ) then                spawnHeart();                 end              end                if( e.count % 21 == 0 ) then             local rand = math.random( 0, 3 );             if( rand ~= 0 ) then                 spawnCoin();             end                  end            end, 0 );     elseif ( action == "pause" ) then         timer.pause( spawnTimer )     elseif ( action == "resume" ) then         timer.resume( spawnTimer )     end end

thanks

I noticed a couple things, but I may be off the trail:

  1. Originally you said 0.25 ms?  I think you meant 0.25 seconds.  I say this because your code has a time of 250 which is 250 ms.

  2. I noticed statements like this in your code:

    if( rand ~= 0 ) then

Be aware that math.random() is not evenly distributed (especially for small ranges like [0,4]) You could get 0 many times in a row using this logic.  If you want a even and random distribution, use a shuffle bag or something like that instead.

http://github.com/roaminggamer/CoronaGeek/tree/master/Hangouts/Tips_and_Tricks/shufflebag

your’e right about the 0.25 seconds this is what I meant.

Ive tried to run the game on an actual device without the part of the random(just the water drops) but still I face the same problem.

any thoughts?

by the way thanks for the link very helpful.

We need to see the timer code really.

Also, math.random only accepts integers. To get a value between 0.8 and 1 do math.random(8/10)/10.

Ive changed the gravityScale’s properties but still got the same problem… 

here’s the code of the spawnController(timer):

local function spawnController( action )     if ( spawnTimer and ( action == "start" or action == "stop" ) ) then         timer.cancel( spawnTimer );     end     if( action == "start" ) then         local spawnTime = 250;         spawnTimer = timer.performWithDelay( spawnTime, function( e )             spawnWater();             if( e.count % 36 == 0 ) then             local rand = math.random( 0, 4 );         if( rand ~= 0 ) then                spawnHeart();                 end              end                if( e.count % 21 == 0 ) then             local rand = math.random( 0, 3 );             if( rand ~= 0 ) then                 spawnCoin();             end                  end            end, 0 );     elseif ( action == "pause" ) then         timer.pause( spawnTimer )     elseif ( action == "resume" ) then         timer.resume( spawnTimer )     end end

thanks

I noticed a couple things, but I may be off the trail:

  1. Originally you said 0.25 ms?  I think you meant 0.25 seconds.  I say this because your code has a time of 250 which is 250 ms.

  2. I noticed statements like this in your code:

    if( rand ~= 0 ) then

Be aware that math.random() is not evenly distributed (especially for small ranges like [0,4]) You could get 0 many times in a row using this logic.  If you want a even and random distribution, use a shuffle bag or something like that instead.

http://github.com/roaminggamer/CoronaGeek/tree/master/Hangouts/Tips_and_Tricks/shufflebag

your’e right about the 0.25 seconds this is what I meant.

Ive tried to run the game on an actual device without the part of the random(just the water drops) but still I face the same problem.

any thoughts?

by the way thanks for the link very helpful.