Debug Logging from Lists
BlitzMax Forums/BlitzMax Beginners Area/Debug Logging from Lists
| ||
Hey all, I'm running into some trouble in debugging my playing card / deck creation code. I'm sure I'm missing something simple here, and I'd love it if someone can point it out. I'm trying to create a card and add it to the DeckList, then prove that it exists via the debug output. The code compiles, but when I run it, it looks like variable s is still set to null. I'm not sure if the problem lies in my attempt to add the card to the list, or in my attempt to log the outcome. Thanks! Type TCard 'type defining a card Const SPADES = 1 Const HEARTS = 2 Const CLUBS = 3 Const DIAMONDS = 4 Field Suit:Int Field Rank:Int End Type Type TDeck '----FIELDS & VARS------ Field DeckList:TList '----METHODS----- Method Create() 'creates the card deck and sets the cards If Not DeckList Then DeckList = CreateList() For Local x:Int = 1 To 13 For Local y:Int = 1 To 4 Local Card:TCard = New TCard DebugLog("New Card Created") Card.Rank = x Card.Suit = y DebugLog("New Card's X and y set to: " + x + "," + y) DeckList.AddLast(Card) Local s:String = String(DeckList.Last()) DebugLog("Object added to list: " + s) Next Next End Method End Type Local GameDeck:TDeck = New TDeck GameDeck.Create() |
| ||
Local s:String = String(DeckList.Last()) DebugLog("Object added to list: " + s) What field do you want do print out into the debug? local my:tcard=tcard(DeckList.Last()) debuglog "Suit : "+string(my.suit)+" Rank: "+string(my.rank) |
| ||
Perhaps I have a conceptual problem on my end? I wanted to print out some sort of representation of the card object... but I guess the card doesn't have a "name" at all because it's just a card object with Suit and Rank... Ok - changed my loops to this: For Local x:Int = 1 To 13 For Local y:Int = 1 To 4 Local Card:TCard = New TCard DebugLog("New Card Created") Card.Rank = x Card.Suit = y DebugLog("New Card's X and y set to: " + x + "," + y) DeckList.AddLast(Card) Local c:TCard = (TCard(DeckList.Last())) DebugLog("Object added to list with suit / rank of: " + c.Suit + "," + c.Rank) Next Next Now works like a charm. Thanks! |
| ||
I wanted to print out some sort of representation of the card object... Well you could print the 'internal name' of an object via the method ToString() if you want. Local mycard:tcard=tcard(DeckList.last()) DebugLog("Object added to list: " + mycard.tostring()) |
| ||
Ah! That was exactly what I was looking for the first time. Thanks. |