New to macs, and even newer to Applescript/programming in general. So I'm just trying to pick up the basics and play around and I made a rock, paper, scissors game. here is the script:
Now, my question is, can i clean that up? I feel like repeating the "set againValue to button returned of result" seemed monotonous. Is there an easier way to do it, or do I have to type it out every single time? I tried setting it to a variable but got confused when I added in the repeat.
I'm looking over some PDFs on basic applescript now but any other advice would be much appreciated
Code:
set againValue to "Yes"
repeat until againValue is not equal to "Yes"
set var1 to "Rock"
set var2 to "Paper"
set var3 to "Scissors"
set question1 to display dialog "Want to play a game?" buttons {var1, var2, var3}
set playerChoice to button returned of question1
set compChoice to some item of {var1, var2, var3}
if playerChoice is var1 and compChoice is var1 then
display dialog "Tie game, I picked \"Rock\" too. Play again?" buttons {"Yes", "No"}
set againValue to button returned of result
else if playerChoice is var1 and compChoice is var3 then
display dialog "Not fair, I picked \"Scissors\". You win! Play again?" buttons {"Yes", "No"}
set againValue to button returned of result
else if playerChoice is var1 and compChoice is var2 then
say "Ha, Ha, I picked paper. You Lose!" using "Zarvox"
display dialog "Play again?" buttons {"Yes", "No"}
set againValue to button returned of result
else if playerChoice is var1 and compChoice is var1 then
display dialog "Not fair, I picked \"Rock\". You win! Play again?" buttons {"Yes", "No"}
set againValue to button returned of result
else if playerChoice is var2 and compChoice is var2 then
display dialog "Tie game, I picked \"Paper\" too. Play again?" buttons {"Yes", "No"}
set againValue to button returned of result
else if playerChoice is var2 and compChoice is var3 then
say "Ha, Ha, I picked scissors You Lose!" using "Zarvox"
display dialog "Play again?" buttons {"Yes", "No"}
set againValue to button returned of result
else if playerChoice is var3 and compChoice is var1 then
say "Ha, Ha, I picked rock. You Lose!" using "Zarvox"
display dialog "Play again?" buttons {"Yes", "No"}
set againValue to button returned of result
else if playerChoice is var3 and compChoice is var2 then
display dialog "Not fair, I picked \"Paper\" you win! Play again?" buttons {"Yes", "No"}
set againValue to button returned of result
else if playerChoice is var3 and compChoice is var3 then
display dialog "Tie game. I picked \"Scissors\" too! Play again?" buttons {"Yes", "No"}
set againValue to button returned of result
end if
end repeat
Now, my question is, can i clean that up? I feel like repeating the "set againValue to button returned of result" seemed monotonous. Is there an easier way to do it, or do I have to type it out every single time? I tried setting it to a variable but got confused when I added in the repeat.
I'm looking over some PDFs on basic applescript now but any other advice would be much appreciated
Last edited by a moderator: