3 Replies - 2732 Views - Last Post: 05 March 2012 - 07:55 AM

#1 mirz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 29-December 11

Random Frames with no repeat

Posted 02 March 2012 - 03:21 AM

Hi!
um..i'm making a quiz game it supposed to have 100 questions but for now it that has 23 questions.
I got the random part it loads a different question when a button is clicked...but the thing is i don't know if it loaded all my question. Also there is a result page at the end how would i load it?
The result page is located (temporarily) in frame 272 and 273
these are my codes on the random part:
on(release) {  
	var x = Math.floor(Math.random() * 22+ 1 );
	gotoAndStop (x)
}


Is This A Good Question/Topic? 0
  • +

Replies To: Random Frames with no repeat

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5505
  • View blog
  • Posts: 11,808
  • Joined: 02-June 10

Re: Random Frames with no repeat

Posted 02 March 2012 - 10:22 AM

Here's the logic I would follow.

Start with an int array with values that correspond to your question array.
So if you have 23 questions you have an int array named "QuestionsAvailable" with values of 0-22

When you generate your random number... lets say 6... Get the value of that item from your QUestrionsAvailable array, then remove that element from the array.

You will start with
QuestionsAvailable[0] = 0
QuestionsAvailable[1] = 1
QuestionsAvailable[2] = 2
QuestionsAvailable[3] = 3
QuestionsAvailable[4] = 4
QuestionsAvailable[5] = 5
QuestionsAvailable[6] = 6
...
QuestionsAvailable[n] = 22


As you remove elements it starts becoming more like this
QuestionsAvailable[0] = 0
QuestionsAvailable[1] = 1
QuestionsAvailable[2] = 4
QuestionsAvailable[3] = 7
QuestionsAvailable[4] = 8
QuestionsAvailable[5] = 12
QuestionsAvailable[6] = 19
...
QuestionsAvailable[n] = 20


So when you get a random number of 5 you will be using question 12 and you will know that question hasn't yet been used.

When QuestionsAvailable has zero elements, you've asked all your questions.

Please take a try at coding a solution now that you have been given a direction to research. Once you have updated your code if you are still having issues please post in this thread rather than starting a new one.


Reminder to new folks: This is homework and we don't provide completed code for homework. Rather we try to help the student comprehend the concept they are struggling with so they can write their own code. They are being graded on their skill not ours.

This post has been edited by tlhIn`toq: 02 March 2012 - 10:23 AM

Was This Post Helpful? 0
  • +
  • -

#3 mirz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 29-December 11

Re: Random Frames with no repeat

Posted 04 March 2012 - 11:33 PM

sorry i can't quite understand...can you explain further...
i'm so new to actionscripting... :helpsmilie: :online2long:
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5505
  • View blog
  • Posts: 11,808
  • Joined: 02-June 10

Re: Random Frames with no repeat

Posted 05 March 2012 - 07:55 AM

Take a look at my blog. The link is in my signature. You'll notice the most recent addition to the homework article is for this very type of quiz homework (because it is coming up so often this semester).

UPDATE:
Just like this question:
http://www.dreaminco...-quiz-lil-help/


This really has nothing to do with ActionScripting. It isn't even language-specific.

It is advice on the overall design logic for your application. It is one way you could keep track of which questions are still available, by taking them out of list once they have been used.

This post has been edited by tlhIn`toq: 05 March 2012 - 08:02 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1