Inputting numbers?

BlitzMax Forums/BlitzMax Beginners Area/Inputting numbers?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

You can use it, but the Input will only appear in the Console Window. For the Graphic Window, you have to write your own Code because a normal Input would freeze the Computer.

A small beginning for a Graphics Input Routine:


Type GInput  ' New Type declared
	Field TempText:String 'The tempoary text where the chars are added
	Field Caption:String ' The Caption what is displayed before getting th Input
	Field X,Y The Screen Coords where the Input is drawn
	
	Function GraphicalInput:Ginput(_Cap:String,X,Y)
		Local In:GInput = New Ginput 'new Instance of Ginput
		In.TempText = "" 'TempText set to Null
		In.Caption = _Cap
		In.X = X
		In.Y = Y
		
		Return In 'Returning the new Instance
		
	End Function
	
	Method Update(OutPut:String Var)
		Char = GetChar() ' Getting the Current pressed key
		
		Select Char
			Case Key_Enter 
				Output = TempText ' If Enter is pressed the TempText will be send to the Output Variable
			Case 0 
				'Nothing to do here 
			Default
				TempText = TempText + Chr(char) ' Adding the char to the TempText
		End Select
		
		DrawText Caption + " ? " + TempText, X,Y 'DrawIng the Input 
	End Method
		
End Type

Graphics 800,600,0,-1

Global Number:String

Global GIn:Ginput = GinPut.GraphicalInput("What Speed",20,20)

While Not KeyHit(Key_Escape)

Cls
If Number = Null Then
Gin.Update(Number)
End If

If Number <> Null Then
DrawText "Current Speed is " + Int(Number), 20,40
EndIf

Flip
FlushMem()
Wend


Well, it is not the best way, I think but it is a starting point.