
-----------------------------------
MysticVegeta
Tue May 24, 2005 4:29 pm

Time counting down simultaneously
-----------------------------------
Hi, There is a section in my program that asks for user input but at the same time, the seconds decrease. How can i make both of them work at the same time without using processes. Processes screw the user input location so bad... :cry:

-----------------------------------
Cervantes
Tue May 24, 2005 4:51 pm


-----------------------------------
That depends on how you're getting the input.  If you're using get, well, let's not go there.  If you're using getch(), that's a little better, because at least you could update your timer in the time between the user's keystrokes!  However, the best way to do this is wrap your getch() statement inside an if hasch statement.  Thus, the getch() code is only executed if there is a key waiting in the buffer.

if hasch then
   getch (input)
end if

Expanding this to include adding the getch() to a variable and adding a timer, we get something like this:

View.Set ("offscreenonly")
var input := ""
var _char : string (1)
var lastTime := -1000
var counter := 11
var fontID := Font.New ("Arial:16")

loop

    if hasch then
        getch (_char)
        exit when ord (_char) = 10  %enter
        if ord (_char) = 8 then %backspace
            if input ~= "" then
                input := input (1 .. * -1)  %chomp off the last char
            end if
        else
            input += _char
        end if
    end if
    if Time.Elapsed > lastTime + 1000 then              %updates every second (1000 milliseconds)
        lastTime := Time.Elapsed
        counter -= 1
    end if

    cls
    Font.Draw (input, 100, 200, fontID, black)
    Font.Draw (intstr (counter), 100, 100, fontID, black)
    View.Update
    delay (10)

    exit when counter 