Resolved IF errors??? Please help!

Discussion in 'Mac Programming' started by wilsonbiggs, Jul 26, 2011.

  1. wilsonbiggs, Jul 26, 2011
    Last edited: Jul 26, 2011

    wilsonbiggs macrumors newbie

    Joined:
    Jul 26, 2011
    #1
    I'm writing an app bundle, and an IF function won't work. I can't use end if, else if, or else... The error is "Expected end of line, etc. but found 'else if'".The if statement is marked by <<<<<<. Here's the code:
    Code:
    display dialog ¬
    	"Welcome to the magiccards.info™ Desktop Search!" with title ¬
    	"Welcome!"
    set search_type to (choose from list {"View as Cards with Scans", "View as a List (Oracle)", "View as Checklist", "View as Scans only", "View as a Spoiler"} with prompt "What type of search will you choose?") as string
    if search_type is "View as Cards with Scans" then set type_search to "card" <<<<<<
    else if search_type is "View as Cards with Scans" then set type_search to "card"
    else if search_type is "View as a List (Oracle)" then set type_search to "olist"
    else if search_type is "View as Checklist" then set type_search to "list"
    else if search_type is "View as Scans only" then set type_search to "scan"
    else if search_type is "View as a Spoiler" then set type_search to "spoiler"
    end if
    set search_item to text returned of (display dialog ¬
    	"What card will you search for?" with title ¬
    	"magiccards.info™ Desktop Search" default answer ¬
    	"" buttons {"Cancel", "Search"} ¬
    	default button 2)
    set AppleScript's text item delimiters to " "
    set theTextItems to text items of search_item
    set AppleScript's text item delimiters to "+"
    set search_item to theTextItems as string
    set AppleScript's text item delimiters to {""}
    tell application "Safari"
    	make new document at end of documents
    	set URL of document 1 to "http://magiccards.info/query?q=" & search_item & "&v=" & type_simple & "&s=cname"
    end tell
     
  2. ehoui macrumors regular

    Joined:
    Jan 27, 2011
    #2
    I'm no AppleScript expert but does the part after the then have to be on a separate line?

    E.g.,
    Code:
    if search_type is "..." then
      set type_search to "card"
    else if search-type is "..." then
      ...
    end if
    
     
  3. sero macrumors member

    Joined:
    Aug 28, 2008
    #3
    I don't really know anything about applescript, but I would try to simplify the code and then build it up when you get it working. Just get a simple if statement to work first. Maybe add some echo commands if that's possible, to see where the code breaks.
     
  4. larswik macrumors 68000

    Joined:
    Sep 8, 2006
    #4
    If you are sending it through a bunch of IF statements you might try a SWITCH to find the right selection.
     
  5. wilsonbiggs thread starter macrumors newbie

    Joined:
    Jul 26, 2011
    #5
    Thank you SO much! That worked! :D

    @Larswik: What's that? :confused:
     
  6. larswik macrumors 68000

    Joined:
    Sep 8, 2006
    #6
    I did not know it was apple script. I was learning Objective C and my brain went to that. I just used a Switch (case) statement the other day to eliminate a 12 IF statements. I know nothing about Apple Script, sorry.
     
  7. wilsonbiggs thread starter macrumors newbie

    Joined:
    Jul 26, 2011
    #7
    Okay! Thanks for trying! :p
     

Share This Page