- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 595
Open
Labels
APIIssues related to TIC80 APIIssues related to TIC80 APIenhancementImprovement of existing feature or adding something newImprovement of existing feature or adding something newwish listWouldn't it be nice if...Wouldn't it be nice if...
Description
I use the TIC-80 fantasy computer to teach my daughter basics of programming, and, given that it is supposed to be a computer, it would be fantastic if we could do something like:
print('What is your name?')
name = input()It would make teaching basic concepts of programming easier and more natural. Also, computers are supposed to have full keyboards -- not just 6 gamepad buttons!
I understand I can accomplish this by importing third-party functions, however it would be a lot simpler/clearer if the input feature was part of the core API.
sprive and svera
Metadata
Metadata
Assignees
Labels
APIIssues related to TIC80 APIIssues related to TIC80 APIenhancementImprovement of existing feature or adding something newImprovement of existing feature or adding something newwish listWouldn't it be nice if...Wouldn't it be nice if...
Projects
Milestone
Relationships
Development
Select code repository
Activity
The-Beesh-Spweesh commentedon Nov 5, 2020
Just so you know, TIC-80 supports a mouse and keyboard as inputs, alongside the four 8-button gamepads.
SDMelipone commentedon Nov 5, 2020
I kind of agree with @sssilver on this, but I can see how it's a big leap.
If TIC-80 were an Apple ][ or Commodore 64, you would have an immediate/direct mode where the interpreter would process the commands as you enter them. Seems to me that's at odds with the scanline/frame structure of TIC-80's design, not to mention the fact that TIC-80 works with multiple languages.
Not sure what @nesbox wants the system to be, long term, but if it had a BASIC-type mode that would be neat. And such an interface could then be amenable to PRINT and INPUT commands to create very basic text console programs to prototype pieces of a larger program.
nesbox commentedon Nov 5, 2020
One user made an example of how to use text input in TIC https://tic80.com/play?cart=449.
Looks a bit difficult, maybe we could add an
input()API function in the future to simplify it.nesbox commentedon Nov 5, 2020
JS code from the cart above:
nesbox commentedon Nov 5, 2020
Another one example https://github.com/nesbox/TIC-80/wiki/code-examples-and-snippets#text-only-game
sssilver commentedon Nov 6, 2020
If we could make an
input()API function, I would be thrilled and do a screen recording of how my seven year old invokes it and share it with you guysjoshgoebel commentedon Jan 29, 2021
What do you imagine that function would do? It can't freeze the machine... TIC() still needs to run at 60 FPS... so I'm not sure this is even possible to do in a function at all (without global state). Anything like "wait for input and enter" is going to require many, many ticks and the string is going to be built up slowly across many frames... hence the global state... I suppose you could pass it a memory location or something that it could use for it's "buffer" though... like passing a pointer in C. :)
Even then you'd still have to allow for two possible return scenarios:
I think some of the examples already show this, but it does get complex.
From example: https://github.com/nesbox/TIC-80/wiki/example-text-only-game
You see this runs every loop so if the user hasn't hit enter yet
input:text()returns an empty string (the signal to keep waiting)... and of courseinput:text()handles drawing the current state of the input to the screen, etc...sssilver commentedon Jan 30, 2021
Personally I would prefer for it to actually block the machine until Enter is pressed. This would simplify things a lot.
Otherwise, if this is unacceptable (why?), it could take a callback that gets invoked when Enter is pressed.
joshgoebel commentedon Jan 31, 2021
I would guess a block is likely incompatible with the design of the entire system. But that's a guess. And yes a callback would certainly be another workable possibility.
For starters there is no way to update the screen if the machine is "frozen" waiting for input. The whole update process depends on the TIC callback.
So I think you're asking tic80 to just be something it's not. Very curious to see what a callback solution might look like in a real small demo.
getc()- slightly higher level character input #1371ManlyPinkPony commentedon Jul 12, 2022
I will say I was learning python about 7-8 months ago, and I'm still learning things like "what is LUA's intended uses and strengths compared to Python?" or any other language really. So admittedly I'm not exactly sure what LUA is all about other than its high "portability" and versatility. And I think it can run on about any piece of hardware that uses C? I'm guessing like doom you can practically run it on an old calculator? (being sarcastic ofc)
In any case, I learned a lot of python things in an interactive shell, and was thinking I would have been tempted to learn LUA from ground zero on TIC-80, just like sssilver describes. In the meantime I'm trying to learn some LUA nuances with Virtual Studio, and learn, like, practical TIC-80 game functions on TIC-80 since I'm learning LUA purely for fun and tryina make some games anyway (for me Python has been more for academic purposes). I must say LUA is already betwizzling me, with its lack of intuitive library importing and its sorta... indiscriminate attitude towards data types like floats and integers. No more x+=1, now x=x+1... just like a lot of basic little things I thought would be obvious but aren't.
Anyway I'm very intrigued by sssilver's idea, it would be awesome if
input()was an internal function in TIC-80. What an awesome educational tool TIC-80 would be if it had something like an interactive shell for running a chunk or something! But also I don't understand the fine details, and I get it if LUA just isn't supposed to do that. Either way, wish me luck, and I hope your kid has lots of fun sssilver. Also I look forward to whatever's next for TIC-80 nesbox! All the best 🤙sprive commentedon Sep 9, 2023
Hi. My comments come with only a couple of hours into the API, but:
+1 to having native text input (ideally with a fallback to keypad-text input like NES did for character names)
I don't think it's a problem if the solution felt ugly (callbacks or other concern): Having a capability is better than not having the capability..
joshgoebel commentedon Sep 9, 2023
Interesting, @nesbox does that mean you intent to tackle this now?
dcaillia commentedon Feb 4, 2024
I developed an approach using lua co-routines, but that is invisible to your client code, which just looks like imperative console IO: example program() :
https://github.com/nesbox/TIC-80/wiki/Code-examples-and-snippets
"Console Program Example"