arrrrggggg

I have a modified code that seems pretty simple. I am having difficulties coming up with solutions to a few problems.
Please bear in mind I have just started using corona and slowly but surely understanding it’s language. please bear with me.

What I need to know is:
The diamonds (suppose to be 7 at a time, one after the other,sometimes act correctly. If acting correctly then there should be 7 diamonds that appear and have a randomness color/shape to them. That doesn’t always happen. Only 4 might show up or 3 or 6. Never consistent.
Also, they should appear randomly (colors/shapes) but at times I might have 5 blue diamonds in a row or 4 red etc…doesn’t seem very consistent. Now I’m sure both of these problems have to do with the math.random functions but can’t figure it out.

So the first part of my problem is that the diamonds do not come out as 7 in a row all the time and the second problem is that the color/shape randomness isn’t very good.
A different problem is being able to move the diamonds. I don’t know what listener I need to set up so that I can move any of the diamonds around at will.

Thanks for any and all help.

here is my code:

local physics = require(“physics”)
physics.start()
physics.setGravity( 0, 5 )

display.setStatusBar( display.HiddenStatusBar )

–local bkg = display.newImage( “bkg-2.png” )

local bottom = display.newImage(“bottom.png”)
bottom.x = 160; bottom.y = 480
physics.addBody( bottom, “static”, { friction=0.5, bounce=0.0 } )

----------------------------------------------------creat diamonds--------------------------------
function newDiamond()
rand = math.random( 120 )
if rand < 10 then
j = display.newImage(“diamond-small-blue.png”);
–j.x = 60 + math.random( 160 )
–j.x = 35
j.y = 190
physics.addBody( j, { density=0.0, friction=0.0, bounce=0.2} )
print( “blue” )
elseif rand < 30 then
j = display.newImage(“diamond-small-red.png”);
–j.x = 60 + math.random( 160 )
–j.x = 35
j.y = 190
physics.addBody( j, { density=0.0, friction=0.0, bounce=0.2} )
print( “red” )
elseif rand < 50 then
j = display.newImage(“diamond-small-purple.png”);
–j.x = 60 + math.random( 160 )
–j.x = 35
j.y = 190
physics.addBody( j, { density=0.0, friction=0.0, bounce=0.2} )
print( “purple” )
elseif rand < 70 then
j = display.newImage(“diamond-small-grey.png”);
–j.x = 60 + math.random( 160 )
–j.x = 35
j.y = 190
physics.addBody( j, { density=0.0, friction=0.0, bounce=0.2} )
print( “grey” )
elseif rand < 90 then
j = display.newImage(“diamond-small-orange.png”);
–j.x = 60 + math.random( 160 )
–j.x = 35
j.y = 190
physics.addBody( j, { density=0.0, friction=0.0, bounce=0.2} )
print( “orange” )
elseif rand < 110 then
j = display.newImage(“diamond-small-yellow.png”);
–j.x = 60 + math.random( 160 )
–j.x = 35
j.y = 190
physics.addBody( j, { density=0.0, friction=0.0, bounce=0.2} )
print( “yellow” )

end
end
------------------------------tells how many diamonds should appear---------------------------------
local dropDiamond = timer.performWithDelay( 500, newDiamond, 7 )

local borderLeft = display.newRect( 13, 175, 2,280)
borderLeft:setFillColor( 255, 255, 255 ) --white
physics.addBody( borderLeft, “static”, borderBodyElement )

local borderLeft = display.newRect( 54, 175, 2, 280 )
borderLeft:setFillColor( 255, 255, 255 ) --white
physics.addBody( borderLeft, “static”, borderBodyElement )

[import]uid: 127842 topic_id: 22278 reply_id: 322278[/import]

For more randomness, try adding this at the start

[lua]math.randomseed(os.time)[/lua]

You can also make your code easier to read here by wrapping it in
< lua > < /lua > brackets (without the spaces around ‘lua’. [import]uid: 10389 topic_id: 22278 reply_id: 88740[/import]

As for moving them around, you can add them to a table and use a for loop to iterate over them and add transitions to move things around. [import]uid: 10389 topic_id: 22278 reply_id: 88741[/import]

I’m looking up randomseed to see what it does. I tried adding it but didn’t work right… Thanks for the tips… [import]uid: 127842 topic_id: 22278 reply_id: 88746[/import]

you know of a tutorial that explains this? I would appreciate it. [import]uid: 127842 topic_id: 22278 reply_id: 88747[/import]

Have a look here:

http://blog.anscamobile.com/2011/09/how-to-spawn-objects-—-the-right-way/ [import]uid: 10389 topic_id: 22278 reply_id: 88796[/import]

Please try to use descriptive thread titles :wink:
http://developer.anscamobile.com/forum/2011/05/05/forum-rules-and-guidelines [import]uid: 52491 topic_id: 22278 reply_id: 88800[/import]