Re: newbie questions

new topic     » goto parent     » topic index » view thread      » older message » newer message
eddo said...

Windows 7; Euphoria 4.0.5; I have discovered that get_key() doesn't respond to my escape key at all. My keyboard may need cleaning! I know there is a response from other situations (control-escape brings up start menu; sometimes I see a funny arrow sign echoed for it. Hard to believe get_key() ignores it. Does anyone know for sure?

Yes get_key() does respond to ESC, but you might actually want to use another function. The get_key() function returns immediately. It either returns -1 (to indicate that there was no key press waiting to be responded to yet) or the code for the current key press. Typically, one uses this function in a loop, so your application can do stuff while there is no key presses waiting to process. You might want to use wait_key() instead. That function waits for the user to press a key, if a key a not already been pressed.

integer keycode 
 
while 1 do 
    keycode = get_key() 
    while keycode != -1 do 
        -- I've got a keystroke to use. 
        process_code(keycode) 
        keycode = get_key() 
    end while 
    -- Do something while waiting for the next keystroke. 
    whatever() 
end while 
 
eddo said...

Also: a program I'm working on crashes with a message on a sequence I have which says "no assignment has been made." Of course not! The sequence holds user choices for an operation. Being empty simply means the user hasn't chosen anything yet, which is perfectly valid - it shouldn't bring my program down. Obviously, I'm doing something stupid - but I'm not sure what. Euphoria shouldn't abort everything just because it runs across an empty sequence, is my thinking.

There is a difference between an EMPTY sequence and an UNASSIGNED sequence. When a variable is declared, and if there is no initial assignment on the declaration statement, the variable has NO VALUE. It is unassigned. A sequence is not assigned by default to 'empty' when it is declared, but it is in a state called 'unassigned'.

sequence S_One 
sequence S_Two = {} 
sequence S_Three = {1,2,3} 
 
? S_Three --> {1,2,3} 
? S_Two   --> {} 
? S_One   --> ** CRASH Sequence has not been assigned anything yet. 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu