Randomizing

bainehollmanbainehollman Member, BASIC Posts: 6

So im making a game that gives an answer when you bush a button. There are 20 different answers to get. How do i make it to where an answer generates randomly. Im thinking of making a scene for each answer or have an answer spawn after you push the button, But i dont know how to make it randomly generate. P.s. there is no right or wrong answer in case you were wondering. Think of magic 8 ball. Please help!! Thanx

Comments

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited December 2015

    Hi @bainehollman

    You make use of the random function in the expression editor.

    make an integer attribute, call it Rand.

    Change Attribute Rand to random(1,20)

    Rule: When Rand = 1
    Display text with first answer

    Rule: When Rand = 2
    Display text with second answer

    Rule: When Rand = 3
    Display text with third answer

    etc., up to 20 answers.

    That's basically it; a shortcut is to use a table.

    There's some additional programming around so you don't pick the same number right after the other, can't find it at the moment tho' - perhaps someone else can help there.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • MoikMoik Member, PRO Posts: 257
    edited December 2015

    Forum won't let me upload a rar :(

    I did this:

    1) Make a Text attribute called "AnswerDisplayer"
    2) Make an Integer attribute called "RandomValue".
    3) Make a Table with 20 rows called "AnswerList"
    4) Put your answers one to a row, down the column.
    5) On the answer rolling button, add a Display Text which is the game.AnswerDisplayer attribute.
    6) Below that on the answer rolling button, add your Mouse Over/Mouse Down rules to make it clickable.
    7) In the "Do" section of the clicking rules, add two Change Attributes.
    8) In the first one, make it go "game.RandomValue = rnd(1,20)" (the random value stuff is under the Functions tab in the first layer of the picker thingy where you select attributes)
    9) in the second one, make it go "game.AnswerDisplayer = tableCellValue(game.AnswerList, game.RandomValue, 1)" (the tableCellValue thing is also in the functions area of the picker)

    So now, any time the player clicks the button, it rerolls the random value, and finds the table row which matches that value, and displays the answer from there.

  • bainehollmanbainehollman Member, BASIC Posts: 6

    you guys are awesome thank you

  • bainehollmanbainehollman Member, BASIC Posts: 6

    FYI...I have a splash screen that fades into a scene with a big red button. i want to be able to push it then have a random answer to pop up whether by going to a whole new scene or spawning an actor. If anyone has a better way of doing this id appreciate so much. Thank you. And thank you GS!!

  • bainehollmanbainehollman Member, BASIC Posts: 6

    One more mention, I have 20 actors that are png's with text. Not sure if i should use them at this point...

Sign In or Register to comment.