Programming Blackjack - assigning numbers to playing cards

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
sel203
Posts: 5
Joined: Wed Feb 11, 2009 3:12 pm

Programming Blackjack - assigning numbers to playing cards

Post by sel203 » Wed Feb 11, 2009 4:15 pm

Hello,

I am very inexperienced at programming but I have managed to set up a simplified version of blackjack for my psychology experiment I am running. I would like to assign numbers of the cards to actual images of playing cards to appear on screen. I have saved each image of the playing cards in separate pdf files but I am struggling to sort out how to make this appear when, say, a '7' comes up.

Would appreciate any advice on this.

Thanks

Sara

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Wed Feb 11, 2009 8:49 pm

Do you need the application to open the pdf in an external pdf reader? or display the image in the stack application?

If you make an array, then either way it should be simple.

for displaying external pdf files:

put "<<the path to pdf file for card1.pdf>>" into tArrCards[1]
put "<<the path to pdf file for card2.pdf>>" into tArrCards[2]
--etc, (you can make this less tedious by "splitting a list" but it doesn't matter how you build the array)

when you get the number of the card you want to display (say in "theCardNumber" variable), then you can:

launch document ("file:" & tArrCards[theCardNumber])


--

if you want to display the images inside the stack, then it would be best to change from pdf format to an image format like png.

Make an image placeholder on your stack the right dimensions to hold the card image. Build an array similar to above.

When you get the number of the card you want to display (say in theCardNumber variable), then you can:

set the filename of image "imgPlaceHolder" to ("binfile:" & tArrCards[theCardNumber])

(If you need to make it portable, it would also be possible to import all the images into the stack and use the id of those (hidden, or placed on another card) to be the array contents. Then you can: set the text of image "imgPlaceHolder" to the text of image id (tArrCards[theCardNumber]) or some similar approach. Lots of ways to skin a cat in Rev.)

sel203
Posts: 5
Joined: Wed Feb 11, 2009 3:12 pm

Post by sel203 » Wed Feb 11, 2009 10:15 pm

Thank you for the advice. I need the cards to appear in the stack so I will try what you suggest.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Wed Feb 11, 2009 10:51 pm

Small corection:

set the filename of image "imgPlaceHolder" to ("binfile:" & tArrCards[theCardNumber])

Should be a simple:
set the filename of image "imgPlaceHolder" to tArrCards[theCardNumber]

Without "binfile:"!


Best

Klaus

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Wed Feb 11, 2009 11:07 pm

Whoops yes. That'd get you the contents of the file inserted as the filename which would certainly not be what you want. Sorry for the confusion.

sel203
Posts: 5
Joined: Wed Feb 11, 2009 3:12 pm

Post by sel203 » Sat Feb 21, 2009 4:53 pm

Hello,

Thank you for you help but I'm struggling! Unfortuately I am very unexperienced - I've tried but I'm not sure how to create an image placeholder? There is a .csv file that indicates which card image I want selected i.e. 10D (10 of diamonds) needs to bring up the pgn image of the 10D in a certain place on the screen. Still not sure how.

Thanks in advance,

Sarah

gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Contact:

Post by gyroscope » Sat Feb 21, 2009 10:27 pm

Hi Sarah, I think I can help here:

Very straightforward: drag an image box (just below the Little Arrows control) from the toolbar onto your stack and name it "imgPlaceHolder"

:)

Post Reply