Types drawtext method always displays 0!

BlitzMax Forums/BlitzMax Beginners Area/Types drawtext method always displays 0!

kaiserpc(Posted 2008) [#1]
Hi,

I'm getting some strange readings from my class when trying call my drawTxt method. It is always just displaying 0 - see below;

type TGameSetup
   field gameText:string
   field xText:int
   field yText:int

method new()
   gameText="test text2"
   xText=40
   yText=40
end method

Function drawTxt()
   DrawText(gameText,xText,yText)
End Function
	
Function Create:TGameSetup()
   Return New TGameSetup
End Function

End Type

Global gameInfo:TGameSetup = new TGameSetup

Graphics 1024,768,0

While Not KeyHit(KEY_ESCAPE)
	
	Cls
	gameInfo.drawtxt() 'this displays 0
	DrawText(gameInfo.gameText,100,100) 'this displays the text
        flip

wend


Apologies about the code not being highlighted/blue etc - but how do you do this?

Anyway, the method always returns 0, but calling the DrawText function and passing in gameInfo.gameText works fine. So why is this failing from the method call?

I'm assuming it thinks it is an integer, but I've defined the field as String.

Regards,

Scott M.


GfK(Posted 2008) [#2]
Change your drawTxt function to a method.


Brucey(Posted 2008) [#3]
You should also try using Strict or SuperStrict at the top of your program. It will catch syntax errors in your code.


kaiserpc(Posted 2008) [#4]
doh!

should have spotted that! :-)

Yep will add the superstrict.

Oh I see the code has been highlighted automatically, how does it know it's code, or has a moderator helped me out?


GfK(Posted 2008) [#5]
A moderator probably did it.

To do it yourself, use {code} put code here {/code} (using square brackets instead of curly ones).

What are the forum codes?


kaiserpc(Posted 2008) [#6]
thx :-)