Page 1 of 1

How do I use Input?

Posted: Sat Nov 17, 2007 12:22 am
by coolw
Ok, it seems simple enough, but I guess not. It's hard to use, and I think it would be nice if Zero could make it easier. For example instead of using a loop to type something in, why not just have it wait untill the enter key is hit? Is there an easier way to use the current command?

Original:

Code: Select all

Repeat
    'UPDATE CONSOLE   
        Color cbwhite    
        If console=OFF Then
            Text 0,0,"Press SPACE to open console"
            If KeyHit(cbkeyspace) Then 
                console=ON
                Locate 10,30
                ClearKeys
            EndIf

        Else
            command$=Input("? ")
            'to enable password field, comment the line above 
            'and uncomment the line below
            'command$=Input("? ","*")
            Text 0,0,"Close console by pressing RETURN"
            If KeyHit(cbkeyreturn)
                console=OFF
                CloseInput 
                ClearKeys 
            EndIf
        EndIf  
Drawscreen
Until EscapeKey()

New Code: (idea)

Code: Select all

a=Input(message$, hide$)
Print a
Just a hint, and I also still need help. :)

Re: How do I use Input?

Posted: Sat Nov 17, 2007 1:03 am
by Jonez
Well input writes text and saves it to a certain variable. It's not hard to use, the example in the manual is just a bit complicated. It's only a good thing that input doesn't stop the program. You wouldn't be able to do even this:

Code: Select all

cow = LoadObject("media\cow.bmp")

Repeat
    txt$ = Input(": ")

    If KeyHit(cbkeyreturn) Then
        //CODE AND STUFF        
        CloseInput()
    EndIf

    MoveObject cow, 5
    TurnObject cow, 5
    DrawScreen
Forever
This was also the example you needed for simplier use of input.

Re: How do I use Input?

Posted: Sat Nov 17, 2007 1:39 am
by coolw
Oh jeez, thanks a bunch :D Saved a lot of coding :)

Re: How do I use Input?

Posted: Sat Nov 17, 2007 10:37 am
by Harakka
You can actually make a custom input which takes only one row. Here's one.

Code: Select all

firstname$  = Input2("What's your first name?")
lastname$   = Input2("What's your last name?")
AddText "Hello, " + firstname + " " + lastname + "!"
DrawScreen : WaitKey

Function Input2(question$)
    Repeat
        answer$ = Input(question + " ")
        DrawScreen
    Until KeyHit(cbkeyreturn)
    CloseInput : ClearKeys
    Return answer
End Function

Re: How do I use Input?

Posted: Sat Nov 17, 2007 12:41 pm
by koodaaja
I don't think that would be added - again. In CB Beta#5 it worked just like that, it was just variable$ = Input("?").