Applescript game help?

Discussion in 'Mac Programming' started by pruzzy, Dec 18, 2012.

  1. pruzzy, Dec 18, 2012
    Last edited by a moderator: Dec 18, 2012

    macrumors newbie

    Joined:
    Dec 18, 2012
    Location:
    Canada
    #1
    Hi! This is my first post here.
    I have been using applescript for some time now (trying out fake viruses, that stuff) and I have recently been trying to make a game. I have a basic question game that is pretty long but it kinda goes like this:
    Code:
    set question to display dialog "Quick! Cats or dogs!" buttons {"Dogs!", "Cats!"} default button 2
    set answer to button returned of question
    
    if answer is equal to "Dogs!" then
    	display dialog "That wasn't fast enough, but nice choice." buttons {"Thanks...", "Your a little random"} default button 2
    end if
    
    if answer is equal to "Cats!" then
    	display dialog "Answer quicker next time." buttons {"I tried my best...", "Your mean"} default button 2
    end if
    
    set question to display dialog "Quick! Snow or sun?!" buttons {"Snow!", "Sun!"} default button 2
    set answer to button returned of question
    
    if answer is equal to "Snow!" then
    	display dialog "I said FAST! And I would have picked the same..." buttons {"Hmmph!", "*sob*"} default button 2
    end if
    
    if answer is equal to "Sun" then
    	display dialog "FASTER! Suns nice isn't it?" buttons {"Yeah...?", "Yes-sir-ee-bob!"} default button 2
    end if
     Those are just 2 of the about 8 questions I have then a conclusion. I wanted to know 2 things.
    1. How do I make it quit? I tried looking around for how I can make it quit but I couldn't find anything so the question about halfway through that asks you if you want to quit, if you press that you want to quit, then it says you can't quit until it's done! How can  I make it so that if you press that you want to quit, it quits, but if you press the other option, it continues?
    2. I want to make a more advanced game that does like:
    "You are sitting home alone eating your pie with ice cream on top. You hear a rustling outside. What do you do?" then there are 2 buttons one says "Go out with a baseball bat" the other "Run upstairs and cry" then if you press the second, "You run upstairs but the door unlocks. You hear footsteps going up the stairs." "Grab a pillow and hide" or "Run out there screaming" and so forth. I don't want it just "random question" "options" "question" "options" and so on.
    Thanks and sorry if this is long.:(
     
  2. macrumors regular

    Joined:
    Jan 3, 2008
    #2
    If you save the script as an application, there is usually an option checkbox for "stay open". Uncheck that, and it will quit when it gets to the end.
    Or, make a dialog that has 3 option buttons on it. The syntax is exactly the same as you have used before. But you can only make a "normal" dialog box with 3 buttons, no more.

    For a choose-your-adventure game, you will need to be a lot more verbose. I am not sure the best option. It will probably involve a lot of sub-functions that return a value, and then the main function that repeats, would take that value and fire off another function based on the previous choice.
     

Share This Page