Game List

hey, im trying to make the list that comes with this script, actually load the games when clicked but im not sure what else to do, any help would be great.

display dialog "Which Game?"
to numsFromChoice(aList, aPrompt, aTitle, mults, CancelText, OKText)
    set numList to {}
    set chosen to {}
    repeat with k from 1 to count aList
        set end of numList to (k as text) & ") " & item k of aList
    end repeat
    set choices to choose from list numList with prompt aPrompt multiple selections allowed mults with title aTitle cancel button name CancelText OK button name OKText
    if choices is not false then
        repeat with j from 1 to count choices
            tell choices to set end of chosen to (text 1 thru ((my (offset of ")" in item j)) - 1) of item j) as integer
        end repeat
        return chosen
    else
        return false
    end if
end numsFromChoice

set Game_List to {"Mario Kart 64", "Super Mario 64"}
try
    set tChoice to numsFromChoice(Game_List, "Choose a Game", "Game List", true, "No Choice", "OK")
    
    if "Mario Kart 64" then tell application "Finder"
        activate
        make new Finder window
        set target of Finder window 1 to folder "Games" of folder "Media" of folder "Desktop" of folder "Frank" of folder "Users" of startup disk
        set target of Finder window 1 to folder "N64 Games" of folder "Games" of folder "Media" of folder "Desktop" of folder "Frank" of folder "Users" of startup disk
        open document file "Mario Kart 64 (USA).n64" of folder "N64 Games" of folder "Games" of folder "Media" of folder "Desktop" of folder "Frank" of folder "Users" of startup disk
        close Finder window 1
    end tell
    
    if "Super Mario 64" then tell application "Finder"
        activate
        make new Finder window
        set target of Finder window 1 to folder "Games" of folder "Media" of folder "Desktop" of folder "Frank" of folder "Users" of startup disk
        set target of Finder window 1 to folder "N64 Games" of folder "Games" of folder "Media" of folder "Desktop" of folder "Frank" of folder "Users" of startup disk
        open document file "Super Mario 64 (USA).n64" of folder "N64 Games" of folder "Games" of folder "Media" of folder "Desktop" of folder "Frank" of folder "Users" of startup disk
        close Finder window 1
    end tell
    
end try

Hi, element432. Welcome to MacScripter.

After the numsFromChoice() handler has run, the value of your variable ‘tChoice’ is either ‘false’ or a list of the numbers of the items chosen by the user. So first you need to see if it’s ‘false’ and exit the script if it is. Then, if not, load each game if the list contains the relevant number:

set tChoice to numsFromChoice(Game_List, "Choose a Game", "Game List", true, "No Choice", "OK")
if (tChoice is false) then return -- or 'error number -128' if you modify the 'try' block.

if (tChoice contains 1) then
	-- Do Mario Kart 64 stuff
end if

if (tChoice contains 2) then
	-- Do Super Mario 64 stuff
end if

But you could economise on the code in a number of ways. You don’t need to open a Finder window (unless you want to, of course!) and the code could be made generic to open both games. I’m not familiar with game files, so I’ve assumed you’re trying to open the correct ones. The entire script would then be:

display dialog "Which Game?"

set Game_List to {"Mario Kart 64", "Super Mario 64"}
set tChoice to (choose from list Game_List with prompt "Choose a Game" with title "Game List" cancel button name "No Choice" with multiple selections allowed)
if (tChoice is false) then error number -128

repeat with thisChoice in tChoice
	try
		tell application "Finder" to open document file (thisChoice & " (USA).n64") of folder "N64 Games" of folder "Games" of folder "Media" of desktop
	end try
end repeat

Obviously it won’t be quite this simple if you later want to include other games which don’t adhere to this naming convention or are in other folders.

Try this. You have to make sure the gameTitles list and gamePaths list are correct… then the rest of this script will work. The script you posted is too complicated. You do not need to open Finder windows to launch files.

-- create 2 lists, the first holds the titles you want to see when you chhose one and the second has the actual paths to the files
set gameTitles to {"Mario Kart 64", "Super Mario 64"}
set gamePaths to {"Macintosh HD:Users:Frank:Media:Games:N64 Games:Mario Kart 64 (USA).n64", "Macintosh HD:Users:Frank:Media:Games:N64 Games:Super Mario 64 (USA).n64"}

-- choose which game to play from the gameTitles list
choose from list gameTitles with title "Games" with prompt "Pick the game to play?" OK button name "Play" cancel button name "Quit"
tell result
	if it is false then error number -128 -- cancel
	set gameTitle to first item
end tell

-- find out the item number in the gameTitles list that was chosen
-- note that the value of "i" will be the number
repeat with i from 1 to count of gameTitles
	if gameTitle is (item i of gameTitles) then exit repeat
end repeat

-- launch the game from the gamePaths list using the item number
tell application "Finder"
	open file (item i of gamePaths)
end tell

Awesome thanks guys! These all worked great and helped me make it not so complicated as I had it haha. Im still new to this stuff but im getting by! :smiley: