Function Left$( str$,n )?

BlitzMax Forums/BlitzMax Beginners Area/Function Left$( str$,n )?

What's happening here is that GetChar is returning 0 for the most part, so you're adding a non printable character to the string every time the code loops, unless you did hit a button.

So if you run the program and type 'asdf', the text will actually be something like this:

********************************a***s***d***f

Where * represents a non printable character. Text will simply skip over them, so when you print that string it'll look just like 'asdf'. But, when you grab the left two characters, they are included, so the result will be '**', i.e. two garbage characters that when you print them out, it will look like an empty string.

To fix it, check that GetChar( ) actually returns a character:

Graphics 800,600
Global text:String
Global a:Int

Repeat
a=GetChar()

'*** change
If a
	
	text:+Chr(a)
	
EndIf

If KeyDown(key_backspace)
	 text=Left(text,2)  'does this mean the left two characters?
EndIf
DrawText text,100,100
Flip;Cls
Until KeyDown(key_escape)