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.
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
– 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
else
set td to (items 1 thru (r - 1)) & (items (r + 1) thru -1)
end if
end tell
end repeat
{sd, (count sd)}
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.