Log In  

I'm not entirely sure if this is bug or my mistake, but i can't figure it out.
Basicly I have code that should save what I'm typing (it's the last line) to a var named code.
However if i add a function for deletion it doesn't work properly:
I can still type, however i have to hold for few seconds before it registers key presses, which does not apply for the backspace.
I also figured out, that only the first code will work properly, meaning if i swap the if with the var set, only typing works.

 if stat(31)=="\b" then
   code=sub(code,0,-2)
 end
 code=code..stat(31)

I'd be really happy to know if it's my mistake or a bug.

P#124786 2023-01-24 20:11

local key=stat(31)
if key=="\b" then
  code=sub(code,0,-2)
end
code ..= stat(31)

this might work.

P#124792 2023-01-24 22:08

hello

P#124808 2023-01-25 04:19
1

Hi @851523

stat(31) returns the pressed key, but then removes it from the input buffer, so you can only call it once. @girres42 has the right idea, but I think they meant: code ..= key, and also you probably don't want to add the backspace character to the string:

code =""
poke(0x5f2d, 1)
function _draw()
    cls()
    print("code:"..code)
end

function _update()
    local key=stat(31)
    if key=="\b" then
        code=sub(code,0,-2)
    else
        code ..= key
    end
end
P#124816 2023-01-25 10:33

@zep & @girres42 thx i couldn't figure that out!

P#124827 2023-01-25 13:37 ( Edited 2023-01-25 13:37)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2023-01-27 11:05:23 | 0.063s | Q:16