Question about random integer!
Hi guys, i'm doing a quiz game where i choose a random integer from 1 to N then i choose the question with the answers. The player choose the answer and then again it start again.
Now how can i say to gamesalad to don't chose 2 times the same number in a game session?????? Thanks a lot!
Now how can i say to gamesalad to don't chose 2 times the same number in a game session?????? Thanks a lot!
Comments
You could also try looking in the code for "my awesome gamesalad game."
hope that helps
kipper
kipper
First add an attribute to your actor to know its rank, let's call it "rank"
first question rank = 2**0
Second question rank = 2**1
Third question rank = 2**2 and so on
As integer are coded on 128 bits you can deal with 128 questions using this method.
Create a game attribute (integer) called "question_memory"
Each time a question is asked, just add its rank number to the question _memory attribute.
Now when a question is selected, to check if it has been asked already, do the following :
Divide question_memory by the rank of the new question. If the integer value of the result is even, the question has not been asked, if it is odd it has already been used.
the formula is :
result = floor(game.question_memory/self.rank)%2
when result = 0 question not asked
when result = 1 question already asked.
If you need a game salad code, i can do
Hope it helps
Bruno
PS : Old_keeper, your solution is good but as integer are coded on 128 bits, it allows only 37 questions before the overflow. But, in a way you made me search in the right direction. Thanks