String bug, or am I missing something here?

BlitzMax Forums/BlitzMax Programming/String bug, or am I missing something here?

Hezkore(Posted 2012) [#1]
Right so... I'm not sure if this is a bug, or if I'm missing something here, but this seems very odd to me!
Basically just write something and press enter, see if the message shows correctly.
SuperStrict
Local ChatStr:String

Graphics(320, 240)

While Not KeyDown(KEY_ESCAPE)
	Local InpChar:Byte = GetChar()
	Select InpChar
		Case KEY_RETURN
			Print("You Wrote: " + ChatStr)
			Notify("You Wrote: " + ChatStr)
			
		Default ChatStr:+Chr(InpChar)
	End Select
	
	DrawText(ChatStr, 0, 0)
	
	Flip(1)
	Cls()
Wend


Last edited 2012


GfK(Posted 2012) [#2]
You probably want to be putting the result of GetChar() into an Int, not a Byte.


Hezkore(Posted 2012) [#3]
Sure sure, but put it into anything and the problem is still there.


GfK(Posted 2012) [#4]
Well, i'm on an ipad right now so can't see what the problem actually is.


Zeke(Posted 2012) [#5]
you are adding chr(0), even key is not pressed. try this:

SuperStrict
Local ChatStr:String

Graphics(320, 240)

While Not KeyDown(KEY_ESCAPE)
	Local InpChar:Byte = GetChar()
	
	If inpchar Then 
		Select InpChar
			Case KEY_RETURN
				Print("You Wrote: " + ChatStr)
				Notify("You Wrote: " + ChatStr)
				
			Default 
				ChatStr:+Chr(InpChar)
		End Select
	EndIf
	
	DrawText(ChatStr, 0, 0)
	
	Flip(1)
	Cls()
Wend


Last edited 2012


Hezkore(Posted 2012) [#6]
Ah yes, that makes more sense.
Thanks Zeke!