News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

How do you use the 'StaticInput' command?

Started by SpellSword, August 15, 2007, 04:05:46 PM

Previous topic - Next topic

SpellSword

I've been trying (And failing :-[ ) to figure out how to make use of the StaticInput command. I've re-read the PB help file on it several times and I'm still not sure.

The use of the command in the PB help tutorial is:
Stuff$(lp)=StaticInput(Digits$(lp,3)+" >")

Here's my currant understanding of it:
| Stuff$() is an array holding strings.
| lp is the variable assigned to the for/next loop. So the array will index the next coordinate as the loop runs.
| StaticInput() is the command in question.
| Digits$(lp,3)+" >" Here's where I run into a problem, I don't know what this is. I think it has something to do with the message that appears by the input as it's being typed.

What I'm trying to do is have the user input a number then dump that into a variable using the StaticInput command.

Clipping from the PB Help file: (For easy reference)
StaticInput
StaticInput Prompt$

Parameters:

    Prompt$ = The Input prompt the request should use.

Returns: NONE


StaticInput is a more traditional input function. Where the function

halts the programs execution and waits for the user to enter a string.

Nothing else can occur while your getting input. Hitting enter key will

make StaticInput return the text that user typed.



FACTS:

* The StaticInput function is part of the "Input" expansion library.

Therefore in order to use StaticInput in program you need to include

that library in your project. To do so, place I.e. #include "Input" at

the top of the your program.

* The StaticInput function halts your programs execution. It will not

exit until the user presses Enter! This is the same behavior as found

in traditional "ANSI" basic compilers using the Input command (ie.

Input "Message";A$. If you want input while your game/program is

running, then you'll need to use an input handler which gives you

asynchronous input. See (Input)

*



Mini Tutorial:




 
 
; Include the Input Library
  #Include "input"
 
 
; load a font
  LoadFont  "Courier New",20,40,0
 
 
; Dim an array to hold the text you type
  Dim Stuff$(10)
 
; Get 10 lines of input  (enter to skip to the next line)
  For lp=0 To 10
   ; Call get Input and use the
     Stuff$(lp)=StaticInput(Digits$(lp,3)+" >")
  Next
 
; Force PB to wait until there's absolute no input from the user
  WaitNoKey
 
; display the text
  Print "---------------------------"
  For lp=0 To 10
     Print "Line:"+Str$(lp)+"  "+Stuff$(lp)
  Next
  Print "---------------------------"
 
 
; show the screen and wait for a key press
  Sync
  WaitNoKey
  WaitKey
 
 
 






This example would output.


 
  ---------------------------
  Line:0  This the first Line of input
  Line:1  And here's another
  Line:2  And another
  Line:3  And another
  Line:4  And another.............
  Line:5  aaaaaaa
  Line:6  xxxxx
  Line:7  zxczxcxzcxc
  Line:8  zxczxczxc
  Line:9  zxczxczxczxczx
  Line:10  And this is the last Line of Text
  ---------------------------

Error Missing Closing Square Bracket
When I dream,
I carry a sword in one hand,
a gun in the other...

Rembrandt Q Einstein

Below is an easier example.  Digits$() takes a value and a number of places you want.  So if you entered Digits$(5,2) the function would give you "05".  If you entered Digits$(22,5), it would give you "00022".  Kevin probably used digits instead of Str$(lp) for formatting reasons, so when it gets to 10 >, it's not a space further right than all the others.

9 >
10 >

or

009 >
010 >


 
#Include "input"

LoadFont "Ariel",1,20,0

AgeInput$ = StaticInput("How old are you?")

Age = Val(AgeInput$)

Print Age

Sync
WaitNoKey
WaitKey


SpellSword

Thank you for the excellent example! I think I completely understand StaticInput's use now.

I'd also like to thank you for including the Val() for converting the string$ and explaining the use of Digits$(,). I didn't realize it was a command, and a very useful one at that! I'll be applying it to what I'm working on almost immediately.

No more ones in the tens column, HUZZAH
When I dream,
I carry a sword in one hand,
a gun in the other...