Computer Science Canada Assigning Values + Importing Multiple Images ? |
| Author: | meagmack [ Sun May 30, 2010 4:45 pm ] | ||
| Post subject: | Assigning Values + Importing Multiple Images ? | ||
What is it you are trying to achieve? <I'm trying to make a blackjack game for my final project> What is the problem you are having? <Basically, I'm wondering if there is a way to import the images of all of the cards, and then assign them a value. So the image of the 2 of clubs would have a value of 2 and so on.Making it loads easier to see who won.> Describe what you have tried to solve this problem <I've tried using the code below, but it came up with an answer of 14003 when I import the pictures, but it is right when I take out the pictures.. which really doesn't help me at all. So I'm not sure if it is something small that I am doing wrong or if it is even possible. LOL. Guidance and suggestions would be MUCH appreciated.> Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <>
|
|||
| Author: | TheGuardian001 [ Sun May 30, 2010 4:59 pm ] | ||||
| Post subject: | Re: Assigning Values + Importing Multiple Images ? | ||||
A variable can only hold one value. If you overwrite that variable (by, say, placing an image ID in it,) the old value is lost. Either have aseparate and corresponding array for the values, or use a 2 dimensional array (an array that holds other arrays), with one set being values and one set being images. 2D arrays are declared as:
Which would create a array that holds 2 other arrays, and each of those arrays holds 52 integers. You access a 2D array in the same way as a normal array, but with an extra subscript:
|
|||||
| Author: | TerranceN [ Sun May 30, 2010 5:20 pm ] |
| Post subject: | RE:Assigning Values + Importing Multiple Images ? |
Or you could use an array of records with the fields image and value. |
|
| Author: | meagmack [ Sun May 30, 2010 5:33 pm ] | ||
| Post subject: | Re: RE:Assigning Values + Importing Multiple Images ? | ||
Thanks everybody, got it figured out now ... or not is there a certain data type that I should be using ? i've tried both int and real with no luck on this code
|
|||
| Author: | TerranceN [ Sun May 30, 2010 7:58 pm ] | ||||||
| Post subject: | RE:Assigning Values + Importing Multiple Images ? | ||||||
is a string, you probably meant
I would still recommend that you use types, it keeps your code cleaner and makes it easier to expand. Also, you can use the mod command and a loop instead of listing every multiple of 13. Finally, the idea of using a multi-dimensional array is to use one of the indices to access one of the integers (either image or value) so there is no reason for this:
|
|||||||