AppleScript help

Discussion in 'Mac Programming' started by littlevish, Mar 11, 2008.

  1. littlevish macrumors member

    Oct 18, 2007
    I'm coding a sports trivia homebrew game in Lua for the PSP. (not important)

    I have made an AppleScript application to make it quicker for me to insert questions. I need to know if it's possible to insert line breaks into the file I'm writing to, so that the code does not get all jumbled up when I open the file later.

    --Trivia Question Maker
    display dialog "Question Table" default answer " "
    set tableInfo to result
    set table to text returned of tableInfo
    display dialog "Question Number" default answer " "
    set numInfo to result
    set num to text returned of numInfo
    display dialog "Enter Question" default answer " "
    set questionInfo to result
    set question to text returned of questionInfo
    display dialog "Choice A" default answer " "
    set aInfo to result
    set choiceA to text returned of aInfo
    display dialog "Choice B" default answer " "
    set bInfo to result
    set choiceB to text returned of bInfo
    display dialog "Choice C" default answer " "
    set cInfo to result
    set choiceC to text returned of cInfo
    display dialog "Choice D" default answer " "
    set dInfo to result
    set choiceD to text returned of dInfo
    display dialog "Correct Answer (1,2,3,4)" default answer " "
    set correctInfo to result
    set correct to text returned of correctInfo
    display dialog "Hint" default answer " "
    set hintInfo to result
    set hint to text returned of hintInfo
    display dialog "Correct Message" default answer " "
    set correctMessageInfo to result
    set correctMessage to text returned of correctMessageInfo
    display dialog "Wrong Message" default answer " "
    set wrongMessageInfo to result
    set wrongMessage to text returned of wrongMessageInfo
    set finalQuestion to table & "[" & num & "] = {question=\"" & question & "\", A=\"" & choiceA & "\", B=\"" & choiceB & "\", C=\"" & choiceC & "\", D=\"" & choiceD & "\", correct=" & correct & ", hint=\"" & hint & "\", correctMessage=\"" & correctMessage & "\", wrongMessage = \"" & wrongMessage & "\"}"
    set theFile to (choose file with prompt "Select a file to write the question to:")
    open for access theFile with write permission
    write finalQuestion to theFile starting at eof
    close access theFile
  2. HiRez macrumors 603


    Jan 6, 2004
    Western US
    Use & "\r" or & "\n" when building your strings to insert returns or linefeeds, respectively.
  3. littlevish thread starter macrumors member

    Oct 18, 2007
    Ah, thanks. :)

    I had tried that before but was missing the quotes.
  4. HiRez macrumors 603


    Jan 6, 2004
    Western US
    Cool, you might want to have a look at AppleScript Studio (installed with Xcode tools), you could put all those form fields on a single page to make it faster, easier, and prettier to enter the info, and make it easier to modify later on.

Share This Page