How do I use Input?

Post your coding questions such as 'how to' here.
Post Reply
coolw
Newcomer
Posts: 39
Joined: Wed Aug 29, 2007 11:17 pm
Location: West Virginia
Contact:

How do I use Input?

Post 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. :)
My car game! (WIP)
viewtopic.php?f=18&t=53

Code: Select all

Coolw is the best! :)
User avatar
Jonez
Devoted Member
Posts: 575
Joined: Mon Aug 27, 2007 8:37 pm

Re: How do I use Input?

Post 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.
-Vuoden 2008 aloittelijan ystävä -palkinnon voittaja-
Image <- protestipelikilpailun voittaja.
Space War
coolw
Newcomer
Posts: 39
Joined: Wed Aug 29, 2007 11:17 pm
Location: West Virginia
Contact:

Re: How do I use Input?

Post by coolw »

Oh jeez, thanks a bunch :D Saved a lot of coding :)
My car game! (WIP)
viewtopic.php?f=18&t=53

Code: Select all

Coolw is the best! :)
Harakka
Advanced Member
Posts: 430
Joined: Mon Aug 27, 2007 9:08 pm
Location: Salo
Contact:

Re: How do I use Input?

Post 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
Peli piirtokomennoilla - voittaja, Virtuaalilemmikkipeli - voittaja,
Sukellusvenepeli - voittaja, Paras tileset - voittaja
Vaihtuva päähenkilö - voittaja, Autopeli - voittaja sekä
Hiirellä ohjattava peli - voittaja B)
koodaaja
Moderator
Moderator
Posts: 1583
Joined: Mon Aug 27, 2007 11:24 pm
Location: Otaniemi - Mikkeli -pendelöinti

Re: How do I use Input?

Post 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("?").
Post Reply