Log In  

(v01 08-12-22)

Cart #background_input-1 | 2022-08-13 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
7


TO LOAD THIS PICO-8 CART, in immediate mode, type: load #background_input .

I had recently received a bit of traffic regarding an old input routine I made found HERE:

https://www.lexaloffle.com/bbs/?tid=31598

so I decided to rewrite it entirely, so it is not coded with GOTO and interrupt main code but made it so it can run in the background additionally.

This means it uses the conventional _update() function and you call it by changing one variable called INPUT to a string value.

Then the input engages - and the rest of your code can continue to run around it. In fact for this demo you can use the arrow keys to move the rainbow circle even as you are typing !

It also remembers the screen and unlike other programs that only remember once what was beneath it, this allows you to continue to draw to its message area even when visible and you will not lose a single pixel of your work.

You also do not need to initialize any variables inside _init(), the whole thing is self-contained.

To make it work you will need two functions firstlineinput() and lastlineinput()

Firstlineinput is 32-tokens and Lastlineinput is 185-tokens.

Quite simply make the first line in your _update() function to call firstlineinput().

Then the last line of your _update() function to call lastlineinput().

function _init()
end

function _update()
  firstlineinput()

  (( your code + graphics ))

  if askname==1 then
    input="what is your name"
  elseif output!=nil then
    print("hello, "..output)
    output=""
  end
  lastlineinput()
end

And that's it ! The rest is handled automatically including updating the screen even if you don't redraw the screen every frame The system is smart and recalls every pixel you draw even if you draw directly on top of it during operation or even as you are typing in text !

To call it, set the global variable INPUT to be something like, "please enter your name."

That will then appear in a frame below, type what you want and press ENTER. Also during name entry only is the "P" and ENTER key taken over so you can press "P" without pausing the system. If you want to pause during text entry, hold the P for a moment and the regular menu will appear.

Press ENTER and the contents of your input are sent to global variable OUTPUT When you are not entering a message the "P" and ENTER key function normally and will pause with a single keystroke.


TECHNICAL:

It does use high memory from 0xF800 to 0xFFFF. As long as you are not using that this program will run just fine.

I am also using global variables that start with an underline and zero. If you have other variables that start with an underline but not a zero after that, you should also not run into any problems.


And there it is !

If you have any questions or comments, feel free to let me know.

P#115676 2022-08-13 00:35 ( Edited 2022-08-13 00:54)

Is the "high memory from 0xF800 to 0xFFFF" for storing the graphics below the text input?

P#125781 2023-02-13 01:46

Yes it is, @Pico_Maker.

Once that lovely stretch of real estate 0x8000-0xFFFF was open for harvest, all kinds of new tricks can be done with it. :)

Although it could be done without using that extended memory, for a bit larger code cost.

P#125786 2023-02-13 03:53 ( Edited 2023-02-14 01:34)

@dw817 I see, thanks!

P#125828 2023-02-13 23:35

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 01:32:13 | 0.031s | Q:22