Trying to figure out error MSG
-
I have here a program that deals cards...
I trying to print on the screen the value of the card and the suit at line 15
but all I get is varible doesent exist......
can anyone see what I did wrong ?clear(darkGreen) image = loadImage ("Kenney/boardgames") suits = ["clubs", "diamonds", "hearts", "spades"] array cards [52} getPack ( ) shufflePack ( ) for i = 0 to 5 loop // this will flip the 5 cards to the screen sprite = cards [ i ] size = getSpriteSize (sprite) setSpriteLocation (sprite, i % 13 * (size.x + 30) +50, int (i / 13 ) * (size.y + 5) + 200) setSpriteVisibility(sprite, true) //-------------------------------------------------------------------------- // Tried to put print command here drawText(30,150, 80 black, valueNo) // tried to print value drawText(40,150, 80 black, suitNo) // tried to print suit //-------------------------------------------------------------------------- drawSprites ( ) update ( ) sleep(0.7) repeat function shufflePack ( ) cardIndex1 = random (52) cardIndex2 = random (52) card1 = cards [cardIndex1] card2 = cards [cardIndex2] cards [cardIndex1] = card2 cards [cardIndex2] = card1 repeat return void function getPack ( ) values = [ [0,"2"], [1,"3"], [2,"4"], [3,"5"], [4,"6"], [5,"7"], [6,"8"], [7,"9"], [8,"10"], [12,"A"], [9,"J"], [11,"K"], [10,"Q"], ] imageNo = 0 for suitNo = 0 to 4 loop for valueNo = 0 to 13 loop cardNo = suitNo * 13 values[valueNo] [0] sprite = createSprite ( ) cardImage = getImage (imageNo) setSpriteImage(sprite, cardImage) setSpriteVisibilty(sprite, false) setSpriteDepth(sprite, cardNo) size = getSpriteSize(sprite) setSprieOrgin(sprite, -size,x/2, -size.y/2) scale = 1.5 setSpriteScale ( sprite, {scale, scale} ) sprite.value = values [valueNo] [1] sprite.suit = suits [suitNo] sprite.imageNo = imageNo cards [cardNo] = sprite imageNo + = 1 if imageNo = 39 then imageNo + = 1 endif repeat repeat return void function getImage (imageNo) cardImage = createImage(140, 190, false, image_rgb) setDrawTarget (cardImage) drawSheet(image, imageNo + 15, {0, 0, 140, 190} ) update ( ) return cardImage //..........................................................................
-
Yeah, you're missing comma's after the 80's in these commands:
drawText(30,150, 80 black, valueNo) // tried to print value drawText(40,150, 80 black, suitNo) // tried to print suit
At least that
-
Also, valueNo and suitNo don't exist at the top level, only within a function later down so as far as the program goes, it knows nothing about them.
-
It looks to me like you're using valueNo and suitNo in your print statements when you want to be using the custom properties you've assigned to the sprites already:
In your
getPack()
function, you have:sprite.value = values [valueNo] [1] sprite.suit = suits [suitNo] sprite.imageNo = imageNo
As @Martin pointed out, the
valueNo
andsuitNo
variables are local to the functions that create them. But, since you're using them to assign information to the custom propertiessprite.value
andsprite.suit
, then storing them in the cards array, you should use those properties in your print statements:drawText(30,150, 80, black, sprite.value) // I've added the missing commas Martin pointed out drawText(40,150, 80, black, sprite.suit)
I thought at first these would have to be
cards[i].value
andcards[i].suit
but since beforehand you writesprite = cards[i]
, this should be correct. -
Working perfectly now.....Thanks again !
-
Excellent! Very glad to hear it :)
-
I've been trying to frend you (Dave) but it says frend not found.
Is your # 5130-4176-1902 ? -
It seems that if you friend waldron your friend screens turns grey,
so now I want to friend fuze team members to stay safe.... -
@kendog400 That should have been fixed
-
Do you know Dave (Fuze Team) friend code ?
-
@kendog400 He doesn't seem to have published it.
-
As @pianofire says the issue with Waldron’s shares has been found and fixed. If you’ve tried again today and it’s not working please do let us know.
-
5139 4176 1902 thats daves, i shouldnt have any issues now been clear for 6 days!!!!!