javascript_terminal_v2
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
javascript_terminal_v2 [2023/11/22 04:53] – appledog | javascript_terminal_v2 [2023/11/27 04:51] (current) – appledog | ||
---|---|---|---|
Line 22: | Line 22: | ||
This separation of terminal mode and command move is central to the goal of escaping the limitations of JavaScript. We do this by creating the nucleus of a state machine and atomizing the execution of instructions inside the context of that machine. This is the 'VM idea'. | This separation of terminal mode and command move is central to the goal of escaping the limitations of JavaScript. We do this by creating the nucleus of a state machine and atomizing the execution of instructions inside the context of that machine. This is the 'VM idea'. | ||
+ | |||
+ | === the input() connundrum | ||
+ | After I published technical demo 2 (this) I added an input() function, which led to a realization that there was no need to use state to operate the game in two modes; what was really required were a series of flags such as ' | ||
+ | |||
+ | I did retroactively add input() to technical demo 2 (see commands HELP and INPUT). String input in the form of an input() function works by giving the system the KEY which will identify the event-command, | ||
+ | |||
+ | < | ||
+ | input(" | ||
+ | return; | ||
+ | </ | ||
+ | |||
+ | Then, when the user presses ENTER, an event will be added to the queue which looks like this: | ||
+ | |||
+ | < | ||
+ | SET_NAME Richard | ||
+ | </ | ||
+ | |||
+ | Then, the game engine will handle this event by changing the user's name. In theory, the game engine will set the name before the next user event is called, either by having a priority queue for state changes, or by assumption (i.e. fiat) that there is no command in the queue which relies on SET_NAME. If so, the system could be programmed to HALT until SET_NAME executes (SET_NAME would be added and the system would wait until it changed to SET NAME < | ||
+ | |||
+ | What if multiple contexts are required; such as, asking three questions in a row? Then, multiple events could be added to the queue: | ||
+ | |||
+ | < | ||
+ | INPUT SET_NAME What is your name? | ||
+ | INPUT SET_CLASS "What is your class (Fighter, Mage)? | ||
+ | INPUT SET_RACE "What is your race (Human, Elf, Hobbit)? | ||
+ | </ | ||
+ | |||
+ | The engine can then throw an INPUT command, and since event processing stops during INPUT, the next question will be asked once the previous one is answered. | ||
+ | |||
+ | What if you need to control state? then you can add queue commands such as: | ||
+ | |||
+ | < | ||
+ | SET_NAME | ||
+ | VAR NAME VALUE | ||
+ | </ | ||
+ | |||
+ | or if you want to be fancy you can index the value by string name; ex. variables[s] where s is the string value of something like | ||
+ | |||
+ | < | ||
+ | INPUT using A | ||
+ | VAR NAME is A | ||
+ | </ | ||
+ | |||
+ | The interpreter can read and write, even to a map (dictionary) if string indexing is not available. | ||
=== The VM idea | === The VM idea | ||
- | The idea is that we get around the limitations of JavaScript (or any modern game engine, or, single threaded environment) by creating a virtual machine that accepts commands, like a computer or cpu that pulls instructions and executes them in the context of some environment. This environment has defined inputs and outputs to the screen, the DOM, or for whatever use it requires. As long as one event can be processed in one 'cycle' then context doesn' | + | The idea was that we would get around the limitations of JavaScript (or any modern game engine, or, single threaded environment) by creating a virtual machine that accepts commands, like a computer or cpu that pulls instructions and executes them in the context of some environment. This is what the original idea was, we would create an event after we processed |
+ | |||
+ | This led to the realization that having two modes wasn't really necessary. There should only be one mode, and when input is needed an input flag could occur which would put characters into a string buffer OR which would trigger a line read from a cursor position, or, on the current line, or context, | ||
- | Carried to an obsessive conclusion, we are essentially writing | + | Eventually it became obvious that the system was falling towards |
- | In practical terms, what this means is we can simulate string input by having command mode switch | + | This topic became too large to fit inside the JavaScript Terminal or JavaScript Netwhack idea, so I will write about it somewhere else, maybe [[JavaScript Virtual Machine]]. |
== Code Commentary | == Code Commentary | ||
Line 851: | Line 897: | ||
== Color.js | == Color.js | ||
Several new colors have been added. Standard greens and ambers based on phosphor wavelength values, as well as look-and-feel approximations of greens and ambers from an IBM 3270. Some look and feel ambers, and some phosphor and/or look and feel consensus opinions on the AppleII and AppleIIc have been added. In a v3, we may also decide to include more colors (such as for VIC-20, C64 and C128) and special fonts to simulate these terminals. For now the extra colors are there to demonstrate how to use the immediate command mode in Terminal (ex. by typing ' | Several new colors have been added. Standard greens and ambers based on phosphor wavelength values, as well as look-and-feel approximations of greens and ambers from an IBM 3270. Some look and feel ambers, and some phosphor and/or look and feel consensus opinions on the AppleII and AppleIIc have been added. In a v3, we may also decide to include more colors (such as for VIC-20, C64 and C128) and special fonts to simulate these terminals. For now the extra colors are there to demonstrate how to use the immediate command mode in Terminal (ex. by typing ' | ||
+ | |||
+ | == Bugs | ||
+ | There were a few bugs. One early bug from v1 is that we have to keep setting the font when we draw tthe character, or for some reason it doesn' | ||
+ | |||
+ | Another bug is related to resizing the terminal. It may be better to simply regenerate the character array instead of creating a whole new terminal because a ' | ||
+ | |||
+ | There is a ' | ||
+ | |||
+ | There was, actually however, a bug in that system I did fix, if it is called with negative cx it doesn' | ||
+ | |||
+ | In that sense there aren't really any other serious bugs, it basicaly works as intended (I checked). If it's something I didn't check then you will be able to work around it in the game code. | ||
== Closing Thoughts | == Closing Thoughts | ||
This is an exciting platform to work with, once it is understood. To understand how to use this platform and how to extend it towards your game, I will discuss my plans for extending this code-base into JavaScript NetWhack. I will put this in a page [[JavaScript NetWhack]]. | This is an exciting platform to work with, once it is understood. To understand how to use this platform and how to extend it towards your game, I will discuss my plans for extending this code-base into JavaScript NetWhack. I will put this in a page [[JavaScript NetWhack]]. |
javascript_terminal_v2.1700628836.txt.gz · Last modified: 2023/11/22 04:53 by appledog