random objects setup

Hey corona community please help me to solve my problem that’s really disturbing me. I’ve questioned about random my objects (level1 = rectangles, level2 = big squares, and level3 = small squares)

Basically I want to randomly choose any level.
I create the drag and drop function to match the object color.

Ex. if level 1 is displaying the “big square” then I will drag the same color to get the right answer, at the end of level 1 it will delete the “big square” object and continue to random the last 2 levels between small square and rectangle.
My problem is I can’t solve the problem that each level can be displayed twice and I want to prevent it to happen

I put my objects value separately inside the game1setup.lua, game2setup.lua, and game3setup.lua

this is the link for my code: http://pastebin.com/A6ps1wKL [import]uid: 74725 topic_id: 12192 reply_id: 312192[/import]

Could you simply do a random number and keep count of how many times each level has been played, stating that if it’s been played twice to pick another number?

Peach :slight_smile: [import]uid: 52491 topic_id: 12192 reply_id: 44394[/import]

Hi Peach I’ve tried to experiment more but it’s still stuck, could you give me your coding version of random function because I’m hard to understand your explanation, sorry for the disturbing demand Peach…
[import]uid: 74725 topic_id: 12192 reply_id: 44500[/import]

I can give you the code for the random function, yes;

[lua]myNumber = math.random (1,3)[/lua]

That would make myNumber a random number between 1 and 3.

You could then use this number to determine what level you wanted to load.

I hope that helps.

Peach :slight_smile: [import]uid: 52491 topic_id: 12192 reply_id: 44555[/import]

yes Peach that’s help me to random my level and how could I eliminate the object that I already played??such as level1 = rectangle then in second and third level won’t display the rectangle again… do I need to use table.remove() to clear each object after change the level??
it’s still confusing me again and again because I tried to make the rectangle only display one time but it always failed.
Please help me with that Peach… [import]uid: 74725 topic_id: 12192 reply_id: 44722[/import]

You could keep track of what has been played with a variable, like levelOne = 0 then when it’s been played once set it to levelOne =1, same for twice. Then if the random number is 1 and levelOne == 2 get a new number or switch to an alternate level.

Removing the object, if it is a normal object, can be done by using object:removeSelf()

Peach :slight_smile: [import]uid: 52491 topic_id: 12192 reply_id: 44773[/import]

yes thanks for your explanation Peach,
My game transition is only between load_game.lua and game.lua,if level1 is right then director will change to load_game.lua to convert the next _G.loadGame into _G.currentGame then after that return back to game.lua for changing to the current level.
The question is how can I define random number if it just take from 1 file(game.lua)???

The other thing I want to know is how to delete the objects if all of my object’s value isn’t inside the same file but I put it in different file?? I created using “params” function for the object value and it also link with the level setup…
or do I need just to delete the object variable from game.lua and it will directly delete the objects value inside the game1setup.lua?? [import]uid: 74725 topic_id: 12192 reply_id: 44931[/import]