Simple user in put example

Monkey Forums/Monkey Beginners/Simple user in put example

navyRod(Posted 2014) [#1]
Can someone show me simple example code of how to use GetString()

Thanks


Danilo(Posted 2014) [#2]
Simplest user input example using GetChar(), without handling special chars (TAB, RETURN, ..):
Import mojo

Class Game Extends App
    Field text:String
    
    Method OnCreate()
        EnableKeyboard()
    End
    
    Method OnUpdate()
        Local char:Int
        Repeat
            char = GetChar()
            If char
                If char = CHAR_BACKSPACE
                    Self.text = text[..text.Length()-1]
                Else
                    Self.text += String.FromChar(char)
                Endif
            Endif
        Until char = 0
    End
    
    Method OnRender()
        Cls(0,0,0)
        DrawText(Self.text,50,50)
    End
End

Function Main()
    New Game()
End



navyRod(Posted 2014) [#3]
Thanks --