Inputting numbers?

BlitzMax Forums/BlitzMax Beginners Area/Inputting numbers?

3Ddoofus(Posted 2005) [#1]
Hi All,
I know this is gonna seem really lame to many but I've just bought BMax and it doesn't seem to be able to do this simple task.
All I want to do is ask the user to enter a number and use that number to control the speed of something but BMax doesn't seem to be able to accept integer input. Is this right?
This is incredibly frustrating and the documentation is next to useless on the subject. I've used BlitzPlus in the past and never come across this problem. Please Help!!
Thanks in advance 3Ddoofus


klepto2(Posted 2005) [#2]
Global InNumber:Int

InNumber = Int(Input("Please enter your Speed : "))

Print InNumber


This is for Console Input only. For Graphical Input you have to write your own code or take a look in the Codearchives.


3Ddoofus(Posted 2005) [#3]
Thanks for the quick response klepto2.
So if I understand you correctly, if I use the graphics command I can't then ask for a number to be input using the input command. Sorry if I seem a bit thick but it seems unbelievable that you can't do something this simple. I am trying to sell my boss on the idea of using blitz but if it won't do something as simple as accepting number inputting then I've no chance!!


Dreamora(Posted 2005) [#4]
You can write a simple while not keyhit(key_return) loop that just collects all pressed signs and outputs them as a single string, thats no problem.

Print and Input are command line / console only command, they have no visual representation. (it wouldn't be of real use anyway as the whole application is on hold while it is waiting for the input)


Jams(Posted 2005) [#5]
Your disbelief is a bit misguided, BMax is extremely powerful, and the function of the input command makes perfect sense. If you're after something more you'll simply need to code it yourself - it is a programming language after all.


3Ddoofus(Posted 2005) [#6]
I've no doubt it is a very powerful program but it seems a fundamental method of user inputting has been omitted. It shouldn't need a page full of code, as seems to be required from the various work rounds that people have produced, and is above my level of experience I might add, to create a method of inputting a simple number. It would appear that BMax is not for entry level programmers, for instance you couldn't do the old hello world program and ask for user input to replace the 'hello world' text!!


klepto2(Posted 2005) [#7]
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:



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


3Ddoofus(Posted 2005) [#8]
"because a normal Input would freeze the Computer". Yep I've found that out :)

I'm sorry but my level of coding experience isn't up to that standard and neither will someone coming to BMax as a newb which limits the audience that this product can hit.
Thanks for the help and the code and I don't want to seem rude cos I do appreciate you taking the time to help, but having to understand exactly how your code is working before I can move on, simply to get a number input is beyond belief.
Thanks again


3Ddoofus(Posted 2005) [#9]
I should have said "trying to understand" how your code is working cos it looks way beyond my level and is giving me sweats just scrolling up and down it! 8D


klepto2(Posted 2005) [#10]
So I've edited th code a bit and added a few Comments.
Maybe you could take look to my Console Module how to add things like Backspace or a simple cursor.


Tom Darby(Posted 2005) [#11]
Here's a less practical, but more easily followed, example:




Strict	' ALWAYS USE STRICT unless you have a very good reason not to.

Graphics 640, 480	' initialize the graphics system.

' declare and initialize variables
Local isRunning:Int
Local userTypedString:String
Local lastCharacter:Int

userTypedString$ = ""
isRunning = 1
lastCharacter = 0


While isRunning = 1


	DrawText "Type something.  Click left mouse button to end program.", 10, 10	' draws instructions to the "back buffer"

	lastCharacter = GetChar()		' gets the character code of the last key hit.  See help on GetChar() for more information.

	If lastCharacter <> 0 Then
	' if GetChar() returned 0, then there was no key pressed, so only add to the user typed string if lastCharacter = 0.
	
		userTypedString$ = userTypedString$ + Chr(lastCharacter)	' Chr() converts character codes to their corresponding letters.
	EndIf
	
	DrawText userTypedString$, 10, 24	' draw the user typed string to the "back buffer".


	Flip			' draws the "back buffer" to the screen
	Cls				' clears the "back buffer"
	FlushMem		' Tells the garbage collector to do its stuff.  Do this once per "draw" cycle.


	If MouseDown(1) > 0 Then	' check to see if the user has clicked their mouse.
		isRunning = 0			' if they have, set isRunning to zero, which will exit the While loop and end the program.
	EndIf

Wend



That's about as straightforward as the graphical text-entry can get. You need to understand that once you start getting into real-time graphics work, a lot of things that seem trivial aren't necessarily so--but they're not necessarily complex, either. You just need to customize behavior to your own needs, as there isn't really a good analog for the "Input" function in a graphical realm; there are simply too many factors to consider and too many different ways in which any given programmer might want to implement text input.


Curtastic(Posted 2005) [#12]
I gotta agree with doofus here.
no seriously


WendellM(Posted 2005) [#13]
I, too, was surprised at Max's lack of a graphical Input when I first encountered it (since Blitz3D handled it fine). This is another reason why I'm eagerly awaiting the standard GUI module... :)


kfprimm(Posted 2005) [#14]
whats the big deal? is it really that hard to take a few extra minutes to right a little code for graphical input?

If you're after something more you'll simply need to code it yourself - it is a programming language after all.

i completely agree.


3Ddoofus(Posted 2005) [#15]
klepto2, sorry if you thought I was having a go at your code, nothing could be further from the truth.
I was just trying to make the point that it seemed as if I needed to jump through hoops to achieve something that to my mind is fairly basic.
Perhaps the fault lies with me in that I am assuming BMax to be an entry level programming language when it is not. The split seems 50/50 here on whether it should be possible straight out of the box, perhaps the 50% who don't see it as a problem are the more experienced amongst us. What I do know is that it has not helped in my introduction to the program and that can't be good for anyone coming fresh to it.
I also think the documentation is very poor.


PetBom(Posted 2005) [#16]
@3DDoofus

I hate to be the one to break it to you, but programming rarely get any easier that what has been discussed above. I think you need to redefine what you put into the term "programming language".

To give an example; If you were to ask a couple of progammers what would be the easiest language to start with, chances are that they would tell you Visual Basic. But the thing is this, doing what you are asking (eg accept a number input) in Visual Basic isn't really easier than doing it in BlitzMax. The difference is that if you use Visual Basic you get an editor suite (Visual Studio) that hides a lot of the implementation in Controls. I.e. It's really easy to add a textbox to a widows form that lets you input your number. But if you were to look at the code behind the textbox Control, you'd pretty soon realize that it is far from simple. The difference is that someone has already done the work for you. That's all fine and dandy if you wan't to do it the way that someone at MS thinks you should do it. If you want to do it in another way, I'm sorry to tell you, it gets pretty complex pretty fast.

BlitzMax does not have a fancy editing suite (I think most users of this forum agree that the IDE is as 'barebone' as it gets). The main reason for this is that the focus of the BlitzMax is creation of games. It is not very likely that two different game devlopers want their textbox to look and act the same. Hence the 'if you want it, build it!' mentality often displayed in these forums.

The important thing is: You need to separate 'programming languges' from 'programming tools'. On that note I'd say that BlitzMax *is* an entry level programming language but it hasn't got a lot of tools (Actually, if you start looking around the site you'll realize that there actually are a lot of tools, in the form of code archives etc. They are just not as nicely presented as in some other products :) )

So I guess all you have to do now is decide what you want to do. Do you want to learn how to program? Well then it's time to roll up your sleves. Do you want to assemble applications from prefabricated bits? Then you probably should look at other products than BlitzMax.

So stop whining and join the fun!

//PetBom


Tom Darby(Posted 2005) [#17]
3Doofus, the docs are weak, yes, but this is just about as straightforward as a programming language can get for game-making. As far as experience goes, it's true that a lot of us are more experienced, but you've gotta practice to get there--we've all put in our time doing stupid little things like making a white ball bounce off the edges of the screen. We've all done the "Big Bertha" style target game to practise physics. We've all done the "guess a number" game.

It's fairly basic to write any of the above examples, but you're still looking at a good number of lines of code to do it--and to be honest, if parsing keyboard input is posing this much of an obstacle to you, you need to set your sights a little lower for the time being. I'm not saying this to be mean or snide; rather, you're going to set yourself up for a whole lot of frustration unless you start out by tackling very basic, boring, move-stuff-around-the-screen stuff.

I strongly recommend you pick up a book or two on game making if you haven't already. I've heard good things about Maneesh Sethi's books (http://http://www.maneeshsethi.com/), though I haven't had a chance to check them out myself. Even when it's made simple, making a game is a lot of hard work and requires fairly extensive programming skill.

Good luck, and do check out some additional resources!

Tom


peltazoid(Posted 2005) [#18]
I was annoyed by input not working outside the console initally. but a few mins later and I had a useable input routine for graphics work. (I wanted to use input as a test to other routines.)

Personally, think of it a bit like c, scanf is crap (yes it can be useful in some situations) but generally you need a to use getc in a loop to get useable input! which involves writing the routine to do it.

Personally I prefer to write my own input routine based on character by character that way it is far easier limit what keys can be used!

just my tuppence worth anyway


kfprimm(Posted 2005) [#19]
I've heard good things about Maneesh Sethi's books

Yeah his books are great i learned how to program in BlitzBasic with his book Game Programming for Teens and i still refer back to it when using BlitzPlus.


3Ddoofus(Posted 2005) [#20]
I apologise to anyone who thought I was 'whining'.
My comments were intended to give an opinion on a subject that was causing me some concern and I thought would be of concern to beginners.

Thanks for the book suggestions I'll take a look at them.

Now I'll say no more on the subject.