black jack

I pirated the following split function from the FAQ:

to split(someText, delimiter)
	set AppleScript's text item delimiters to delimiter
	set someText to someText's text items
	set AppleScript's text item delimiters to {""} --> restore delimiters to default value
	return someText
end split

When I try to use the function I get an error that says “Finder got an error: Can’t continue split.” Can someone help me figure out what I am doing wrong? TIA.

set pieces to split(web_file, ":")

A small correction:

set pieces to split(web_file as string, ":") 

I haven’t tested your handler but if it’s called from within a Finder tell block, this might help.

set pieces to my split(web_file as string, ":")

– Rob

That was it. Thanks.

im not sure where to put this, its a scripting question but it has to do with xcode.
i am making a blackjack game so far i have the hit me button that randomly selects a card and gives it to you. i want a way to make sure not to give someone more than 4 of the card, im not sure how to do this witout a huge if then list
heres what i have so far

set old_set to content of text field "cards" of window "black jack"
	set card_list to {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"}
	set new_card to item (random number from 1 to (length of card_list)) of card_list
	set old_set to old_set & "     " & new_card
	set content of text field "cards" of window "black jack" to old_set

is there any way to make a number of times the same card can be drawn cap? without a huge if then list

There are several ways of doing this. One is to keep a list of already-dealt cards and compare this card to the already-dealt list.

An alternative is to start with a list of all cards (rather than a list of all values) and clear the list item each time a new card is dealt, like:

[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]


I was thinking that you might want to shuffle the deck at the start. This way you don’t need to wait for the cards while you’re playing.



Something like this for shuffle works:

property the_suits : “SHCD”
property the_nums : “AKQJT98765432”

– make a new deck
set d to {}
repeat with s in the_suits
repeat with n in the_nums
set c to (n & s)
set end of d to c
end repeat
end repeat
– shuffle the deck d
set sd to {} – shuffled deck
set td to d – temp deck, save d for reset
repeat with u from 52 to 1 by -1
set r to (random number from 1 to u)
set c to (item r of td) – the card
set end of sd to c
tell td
if r = 1 then
set td to rest
else if r = u then
set td to reverse of rest of reverse
set td to (items 1 thru (r - 1)) & (items (r + 1) thru -1)
end if
end tell
end repeat
{sd, (count sd)}

Now, deal the cards.

I’ll look at it more tomorrow.


That’s a good idea, Kel… more closely emulates what happens in real life, and you’re guaranteed to get unique cards each time just by walking through the list.