Input() in Blitzmax?
BlitzMax Forums/BlitzMax Beginners Area/Input() in Blitzmax?
| ||
How do I receive numerical input in Bmax? For example, B3d I could use TotalLevels=Input(). |
| ||
http://blitzbasic.co.nz/bmdocs/command_list_2d_cat.php?show=Input |
| ||
Ok, but I need a promt for user input. Everything on that list seemed to return a keycode with no user promt. I want the actual value of the key, not the keycode. |
| ||
http://blitzbasic.co.nz/bmdocs/command.php?name=Input&ref=2d_cat |
| ||
Sorry,but I need intergers not strings. |
| ||
Int(str$) |
| ||
Ok. I got that. How do you get it to show up on graphic screen and not the console? This was so simple in B3d. I guess while we're on the topic, how would one go about this in Maxgui? Last edited 2012 |
| ||
In MaxGUI? Well, add a text field and type stuff in there :-) |
| ||
"add a text field and type stuff in there" lol. Well ya, but how do I get from there to an interger varaible? I want to be able to type in a number and assign it to an int variable. |
| ||
Well, you do what Jesse says, which is to cast your String to an Int. I heartily suggest you visit the Tutorials section of the website and work your way through the stickied "The MaxGUI Beginner Tutorial Series". It'll teach you a lot about how to use MaxGUI for stuff. |
| ||
Cast what string into an Int? Everything is in gadgets/event gadget actions. How the hell do you get from gadgets or text gadgets etc. to say a string variable that i can even invoke Int? I have been going through the tuts, but all I can get out of it is keying some text into an textfield to display in labels and such. Thats nice and all to be able to display something I typed in, but I want to take input and assign it to a variable. Like typing the number 4 in, hit enter and assigning to an integer variable. No clue at this point how to do that in maxgui from what i've gathered so far from the tuts. Perhaps you can point me to the specific tut that will explain this for me? |
| ||
Tutorial 6 discusses TextFields. Specifically, it shows that TextFieldText() will return a String of the contents of the TextField gadget. Now that you know how to get a String from a TextField, it's simply a case of setting that string into a variable. Unfortunately, tutorials don't show every possible use for some functionality or other, so you need to look at what it does show you, which in this case is enough to find out how to extract the String data, and then you sit and work out how to do the rest yourself. That's the fun part of programming ;-) Some pseudo code… on some action : numberVariable = Int(TextFieldText(gadget)) |
| ||
Yep, I don't mind figuring stuff out, but sometimes a simple code example cuts through the fog. Thank you. |
| ||
Hello, TextFieldText() has been superseded with GadgetText() . Here is a little sample... -Henri Last edited 2013 Last edited 2013 |
| ||
Thanks Henri. Very helpful. I was wondering how i was going to reset the textfield to zero. I'm learning. Cheers & happy new year! |
| ||
Another little helpful tip is that you can use SetGadgetFilter for textfields and textareas to allow or disallow certain characters. For example you say you'd like integers only, so you would also restrict the characters in the actual textfield to numbers only. Add this anywhere outside of the main loop. Edited due to not testing the code before posting. Added Asc(). :P Last edited 2013 |
| ||
Hey col, Just got around to trying your code and I can't get it to work. I keep getting a "Compile Error: Function can not return a value" |
| ||
SuperStrict Graphics 800,600 Function gfxInput:String(prompt:String="",x:Int=-1,y:Int=-1,reset:Int=False) Global result$ If prompt="" And x=-1 And y=-1 Then Local r$=result$ If reset=True result="" Return r EndIf DrawText prompt+result,x,y Local width:Int=TextWidth(prompt+result)+1 If MilliSecs()/500 Mod 2=0 Then DrawLine x+width,y,x+width,y+TextHeight(prompt+result) Local char:Int=GetChar() If char Select char Case 13 'return Return result Case 8 'backspace If result.length>0 Then result=result[..result.length-1] Default result:+Chr(char) End Select EndIf Return Null End Function While Not(KeyDown(KEY_ESCAPE) Or AppTerminate()) Cls If gfxInput("Enter name:",100,100) Then Notify gfxInput(,,,True) Flip Wend |
| ||
Thanks, but not what i'm looking for at the moment. I would like to restrict characters to numbers in some of my textfield gadgets. On a side note though, I would like to know how to get a prompt on a graphic screen instead of the console. :) |
| ||
I would like to know how to get a prompt on a graphic screen instead of the console You can write your own "graphics console" routine, like the example Zeke has given in his last post. |
| ||
Egad. All that to produce a simple prompt on a graphic screen? Is there a more newb friendly way? It would take me a while to unpack and understand Zeke's example. So simple in B3d. variable=Input() ta-da! |
| ||
Also the INPUT on B3D is "out-of-date" and only displays the prompt on the screen, because the console is together with the graphic on the same window. But all console commands destroy your graphic content in this "solution". So a better graphic solution take care about not to use the console for user inputs. What is the problem of writing the function as you need it? Zeke's function is a substitution the INPUT(). So why not add it and use it without understanding? You also never thought about how INPUT() worked on B3D! |
| ||
Hiya, You must be using SuperStrict. I usually use Strict which defaults return values to Int. Here's a working MaxGUI example using SuperStrict... Last edited 2013 |
| ||
Ah yes, That was it. Thanks Col. Midimaster, As you say, I can adapt the code without entirely understanding it yet,but since a function has to be created to accomplish what I need,it will be nicer to understand it more thoroughly.User input is my need so your point about the console is noted. Thanks. |