Something strange and weird in math.random and transition please help...

Hi everyone…

I know it’s a long post, but I try to make this work, and I can’t

Please I do need your help, thanks

I want to make a little game, asking questions…

I have 6 objects, and I make a transition to each object to a different position ( 6 positions total )

I get the images of the objects from a table

symbols = {     [1] = "notes/object1.png",     [2] = "notes/object2.png",     [3] = "notes/object3.png",     [4] = "notes/object4.png",     [5] = "notes/object5.png",     [6] = "notes/object6.png" -- and so on ( I have 87 objects here, or 87 images )

So I get a math.random number, 1 to 6

    local change = math.random ( 1, 6 )

I and type this

if change == 1 then         bolita1 = display.newImageRect (simbolos[numerito1], 230, 204)         sceneGroup:insert(bolita1)         bolita1.x = display.contentCenterX         bolita1.y = display.contentCenterY         bolita1:scale(.4, .4)         bolita1.alpha = 0         local function bolita1Listener ()             composer.gotoScene("wrongpage")         end         bolita1:addEventListener ("tap", bolita1Listener)                  bolita2 = display.newImageRect (simbolos[numerito2], 230, 204)         sceneGroup:insert(bolita2)            bolita2.x = display.contentCenterX         bolita2.y = display.contentCenterY         bolita2:scale(.4, .4)         local function bolita2Listener ()             composer.gotoScene("wrongpage")         end         bolita2:addEventListener ("tap", bolita2Listener)                  bolita3 = display.newImageRect (simbolos[83], 230, 204)         sceneGroup:insert(bolita3)         bolita3.x = display.contentCenterX         bolita3.y = display.contentCenterY         bolita3:scale(.4, .4)         local function bolita3Listener ()             composer.gotoScene("q2")         end         bolita3:addEventListener ("tap", bolita3Listener)              bolita4 = display.newImageRect (simbolos[numerito3], 230, 204)         sceneGroup:insert(bolita4)         bolita4.x = display.contentCenterX         bolita4.y = display.contentCenterY         bolita4:scale(.4, .4)         local function bolita4Listener ()             composer.gotoScene("wrongpage")         end         bolita4:addEventListener ("tap", bolita4Listener)              bolita5 = display.newImageRect (simbolos[numerito4], 230, 204)         sceneGroup:insert(bolita5)         bolita5.x = display.contentCenterX         bolita5.y = display.contentCenterY         bolita5:scale(.4, .4)         local function bolita5Listener ()             composer.gotoScene("wrongpage")         end         bolita5:addEventListener ("tap", bolita5Listener)              bolita6 = display.newImageRect (simbolos[numerito5], 230, 204)         sceneGroup:insert(bolita6)         bolita6.x = display.contentCenterX         bolita6.y = display.contentCenterY         bolita6:scale(.4, .4)         local function bolita6Listener ()             composer.gotoScene("wrongpage")         end         bolita6:addEventListener ("tap", bolita6Listener)     elseif change == 2 then           -- // I do the same for all the other 5 numbers     else          -- // Keep going like that It's a long CODE     end

So finally in the SHOW scene ( in the “did” part ) I do this

local function uno1()     local numero1 = math.random ( 1, 6 )     if numero1 == 1 then         transition.to(bolita1, {time = 450, x = pos1.x, y = pos1.y, alpha = 1, transition=easing.outBounce})     elseif numero1 == 2 then         transition.to(bolita2, {time = 450, x = pos2.x, y = pos2.y, alpha = 1, transition=easing.outBounce})     elseif numero1 == 3 then         transition.to(bolita3, {time = 450, x = pos3.x, y = pos3.y, alpha = 1, transition=easing.outBounce})     elseif numero1 == 4 then         transition.to(bolita4, {time = 450, x = pos4.x, y = pos4.y, alpha = 1, transition=easing.outBounce})     elseif numero1 == 5 then         transition.to(bolita5, {time = 450, x = pos5.x, y = pos5.y, alpha = 1, transition=easing.outBounce})     else         transition.to(bolita6, {time = 450, x = pos6.x, y = pos6.y, alpha = 1, transition=easing.outBounce})     end end timer1 = timer.performWithDelay ( 50, uno1, 100 )

I get another math.random to send the images to a different position

I know it’s not the best way to write the same thing

but that’s all I know.


THE PROBLEM and weird stuff

The code works fine… relaunch…fine…relaunch…fine

after a few times 6 or seven

One of the images comes REALLY BIG, and another image “really small” – WEIRD!!!

I relaunch… fine, so I play a few times and there it is – the big image again…

I see no where in the code a change of :scale

or something that makes that big image show

and also why it works fine for many times, and then not works fine?


If you can tell me a better or easy way to do the same thing I will appreciate it a lot.

Thanks for your time

When you are using transitions and an image sometimes appears very large or small it is often because an exception is happening during the transition initialisation and the transition aborts while scaling the image being transitioned. I assume the code above is not your whole code, so I can’t really say where that is happening, but what errors do you see in the console?

You say that you are not scaling, but you have :scale(.4,.4) a number of times in your code.

Thanks for the answer…

It might be one of those exceptions that you said… I don’t know…

But I found another way of making a similar game, so I will use that one.

But I will read more on that exceptions on transition.

Thanks

When you are using transitions and an image sometimes appears very large or small it is often because an exception is happening during the transition initialisation and the transition aborts while scaling the image being transitioned. I assume the code above is not your whole code, so I can’t really say where that is happening, but what errors do you see in the console?

You say that you are not scaling, but you have :scale(.4,.4) a number of times in your code.

Thanks for the answer…

It might be one of those exceptions that you said… I don’t know…

But I found another way of making a similar game, so I will use that one.

But I will read more on that exceptions on transition.

Thanks