Hi I have a problem generating random scenes using composer. The flow is when I press the button it should go to scenes randomly then when I press again the button in the present scene it should still be going in scenes randomly and so on and forth until it reach its limit then going back to the main menu. Please help ^^
Difficult to help without seeing your code and exactly how you’re trying to achieve this.
Here are a couple of posts describing scene randomizing:
http://forums.coronalabs.com/topic/48995-how-to-choose-random-lua-file-when-storyboardgotoscene/
http://forums.coronalabs.com/topic/27576-how-to-randomize-scene-with-out-repeat/
here is a sample
first when the “tap here” is pressed it will generate random scenes from scene1-5 they should only show once
example:
first attempt = 5,3,2,4,1
second attempt = 1,4,2,5,3
third attempt = 2,3,5,1,4
so on and forth, after the all the scenes are shown it will go to the main menu of the application
Please help me … i really need to finish my project T.T
The cynical me might start to think this is some kind of project from a course. As the post that @Panc has pointed you towards has all the information you need to solve this problem. And when you look at the dates september last year this type of question came up and now september this year this type of question comes up??? -
Using tables and shuffle is the way to go.
T.
sorry i tried almost everything but when I run it the screen turns black. I do it in a prototype application and have the .lua files and other objects present in the directory. I don’t either understand fragmented codes, I am a learner that need to see the whole code of process then I can easily dissect and digest it easily. . . Sorry =(
Let’s separate this into parts, as this is the best way to solve any problem.
-
You want to have a function that chooses from a sequential set of numbers, but only uses a number once.
-
You want to have several scene modules which correspond to “levels” in your game (I’m assuming).
-
You want your game to progress automatically from one scene to another in the sequence generated in step 1.
You want to separate your project into these separate parts. Are you having problems with all three of these aspects? Do you have the randomization and sequencing down, and are having a problem with getting the code to progress through scenes? Are you positive your scenes are set up correctly and you can go to each individually, outside of this randomization technique?
Yes I have a problem on that three parts and last would be the result scene (consistent as the last scene to be shown ). I may either have a problem where to put and what code needed to be typed
Each of those parts is going to take some investigation and education on your part to achieve. I can guarantee that questions relating to each of those parts have been asked (and answered) in the Corona forums here. I already put up a link for scene randomization, which should give you a pretty good starting point.
It’s important for you to separate each of these parts, so that you can confirm that the first part works outside of the scene management logic. Then, you want to confirm that your scenes work without your “randomized progression” logic. Then you can put the first two parts together to achieve the third part.
If i used this code:
- for i=1, 3 do
- postable[i]=i
- end
- local function shuffle(t)
- local iterations = #t
- local j
- for i = iterations,2, -1 do
- j = math.random(i)
- t[i], t[j] = t[j], t[i]
- end
- end
- shuffle(postable)
- for i = 1 , (#postable) do
- print(postable[i] )
- end
how can i go to random scenes? do i need to put all the scenes in one lua script? how can I go to result scene which always be at the last?
It is working on terminal but the questions are still not answered. I am thinking of getting the indexes of each array but dont know what the code is something like this if possible:
TERMINAL:
3
2
1
CODE:
composer.gotoScene(array name[1], “animation”, “delay”);
Thanks for the help of those who post and answered the question xDDD
Here’s an update when I create a prototype of the array_shuffle and combines the built in sample program of composer module it works but only on the first scene the other scenes are not:
Flow:
1st attempt = 2,3,4,1
2nd attempt = 1,2,3,4
3rd attempt = 4,1,2,3
4th attempt = 3,4,1,2
as you observed only the first scene do randomizing the others are just sequentially display. I need the other scenes shuffle also
Terminal:
4
3
1
2
Expected flow:
1st attempt = 4,3,1,2, result
when the button is press and showing the last page as result
suggestions and/or a helping hand will be great appreciated =)
Difficult to help without seeing your code and exactly how you’re trying to achieve this.
Here are a couple of posts describing scene randomizing:
http://forums.coronalabs.com/topic/48995-how-to-choose-random-lua-file-when-storyboardgotoscene/
http://forums.coronalabs.com/topic/27576-how-to-randomize-scene-with-out-repeat/
here is a sample
first when the “tap here” is pressed it will generate random scenes from scene1-5 they should only show once
example:
first attempt = 5,3,2,4,1
second attempt = 1,4,2,5,3
third attempt = 2,3,5,1,4
so on and forth, after the all the scenes are shown it will go to the main menu of the application
Please help me … i really need to finish my project T.T
The cynical me might start to think this is some kind of project from a course. As the post that @Panc has pointed you towards has all the information you need to solve this problem. And when you look at the dates september last year this type of question came up and now september this year this type of question comes up??? -
Using tables and shuffle is the way to go.
T.
sorry i tried almost everything but when I run it the screen turns black. I do it in a prototype application and have the .lua files and other objects present in the directory. I don’t either understand fragmented codes, I am a learner that need to see the whole code of process then I can easily dissect and digest it easily. . . Sorry =(
Let’s separate this into parts, as this is the best way to solve any problem.
-
You want to have a function that chooses from a sequential set of numbers, but only uses a number once.
-
You want to have several scene modules which correspond to “levels” in your game (I’m assuming).
-
You want your game to progress automatically from one scene to another in the sequence generated in step 1.
You want to separate your project into these separate parts. Are you having problems with all three of these aspects? Do you have the randomization and sequencing down, and are having a problem with getting the code to progress through scenes? Are you positive your scenes are set up correctly and you can go to each individually, outside of this randomization technique?