Question about random integer!

v00d0v00d0 Member Posts: 143
edited November -1 in Working with GS (Mac)
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!

Comments

  • SamXOOO7SamXOOO7 Member Posts: 47
    Hey, I'v been trying to figure out how to do that for quite a while. But if your willing to pay Tshirtbooth successfully made a template for it, but it was $10 last i checked. http://gamesalad.com/forumstopic.php?id=23421

    You could also try looking in the code for "my awesome gamesalad game."
  • old_kipperold_kipper Member Posts: 1,420
    a simple thing to do is use random, and make an 'add one' to the question number if it is already taken. Also have a rule that rolls over the top back to zero in case you hit the roof.

    hope that helps

    kipper
  • v00d0v00d0 Member Posts: 143
    mmm i don't understand! ive to pay if i wanna know how to use random exception?
  • v00d0v00d0 Member Posts: 143
    OMG isn't easy! any other way?
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    here ya go

  • old_kipperold_kipper Member Posts: 1,420
    I think the problem with using TSB's method is that unless you store and address the used numbers that the numbers/questions can recur within any group larger than two if you don't have a limit of two questions per round. I don't think there is a way of not repeating without storing the numbers already chosen in a large group of questions.

    kipper
  • SamXOOO7SamXOOO7 Member Posts: 47
    That's not the same thing John, he wants non repeating numbers through the whole game, that tutorial is for only non repeating numbers in a row not throw the whole thing.
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    Yes but you can take those methods and adjust them to your needs to run threw the whole game or however you wish. You gotta put in some effort ;)
  • v00d0v00d0 Member Posts: 143
    I'm trying now! thanks everybody...for now!
  • v00d0v00d0 Member Posts: 143
    if i have 50 questions, the only way that i found is to create 50 attribute where it store the old numbers :S
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    v00d0 said:
    if i have 50 questions, the only way that i found is to create 50 attribute where it store the old numbers :S

    Yep thats most likely how you'll have to do it. The amount of attributes doesn't effect anything though.
  • v00d0v00d0 Member Posts: 143
    thanks m8! i hope they will implements something like arrays because you waste a lot of time with those attributes for multiple items of the same type
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    v00d0 said:
    thanks m8! i hope they will implements something like arrays because you waste a lot of time with those attributes for multiple items of the same type

    No problem and yep thats why you need all the attributes because we dont have arrays. But there on the roadmap so there coming :)
  • old_kipperold_kipper Member Posts: 1,420
    There is another way that would use a single attribute and that would be to add prime numbers for each of the questions into one integer and then resolve them to divisors to see what was being used. I am not sure how fast it would be or if you could fit the calculation easily into the expressions editor but I might give it a go when I have some time free.
  • v00d0v00d0 Member Posts: 143
    Guys, if i create 50 scene the game will be playable without lag etc on th eipgone 3g,3gs,4g or it will have some kind of problems?
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    You can have 50 scenes no problem. Its not the ammount of scenes but whats in them that matters.
  • v00d0v00d0 Member Posts: 143
    ye but if I've 50 scene with 50 background that's all the same for each scene then it multiply it for 50 or is just 1? stupid question but i need to know some more details, sry guys!
  • brunos78brunos78 Member Posts: 2
    smart solution Old_kipper, i will try
  • brunos78brunos78 Member Posts: 2
    V00D0, I have a solution for problem.
    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
Sign In or Register to comment.