Twine javascript

Glacial_cry

Newbie
Jul 26, 2021
18
34
I have been messing around with a game idea that i have by attempting to learn stuff through "reverse-engineering" some of the more prominent HTML games out there. I dont exactly know if thats a bad idea or a waste of time, as i have never attempted to make games before, i only have mid-high level c++ experience and moderate amount of Python grasp, and never really used them for anything other than occasional trivial personal projects. So my question is this;

I can understand the vast majority of the story format related "code", HTML&CSS as well without any real problems. But when i look at the javascript sheet, for most of the games it just goes and goes and goes to forever and ever with nonstop code about stuff that arent even in the game or mentioned anywhere in the passages etc. Do devs themselves write all this code from scratch? Or are they getting it from somewhere else as a public asset or something(some of the blocks have comments like "twine-user-script #7"etc)? Like i know *some* devs kind of "make their own engine" and some devs are actually teams of multiple people working on the same game, but apart from those rare cases, most of these games are made by a single person.

And when i try to understand the code with my little to no experience with javascript, i see that the same thing can also be achieved through a story format code or HTML itself. Apart from minigames and such, if i can achieve the same thing with say Sugarcube or HTML, is there a technical reason or benefit for using javascript instead?

Thanks in advance, pardon the butchering of language and terminology.
 

guest1492

Member
Apr 28, 2018
350
288
For Twine games, the story format is the engine. Most Twine games here are made with the SugarCube format (and it's the only one I'm familiar with). SugarCube has many APIs that you can choose to use which requires the use of JS.

Examples of configuration settings using the :
You don't have permission to view the spoiler content. Log in or register now.

Example of adding a font family setting through the :
You don't have permission to view the spoiler content. Log in or register now.

Example of updating variables when loading a save from an older version of the game through the :
You don't have permission to view the spoiler content. Log in or register now.

Even if you are not familiar with JS and don't intend to nor have any need to use any of the APIs yourself, you might want to use some third party macros. I've seen plenty of games use Chapel's , , and macros.

SugarCube is just sugared JS. Every time you are using the <<set>> or <<if>> macros, you are using JS. The only difference is that you are using $varName instead of State.variables['varName'].
 
  • Like
Reactions: osanaiko

Alcahest

Engaged Member
Donor
Game Developer
Jul 28, 2017
3,481
4,322
I can understand the vast majority of the story format related "code", HTML&CSS as well without any real problems. But when i look at the javascript sheet, for most of the games it just goes and goes and goes to forever and ever with nonstop code about stuff that arent even in the game or mentioned anywhere in the passages etc. Do devs themselves write all this code from scratch? Or are they getting it from somewhere else as a public asset or something(some of the blocks have comments like "twine-user-script #7"etc)?
The "twine-user-script" comments are for javascript (files) added by the game dev. They code that themselves or some of it could be taken from other places, like Chapel's macros that was mentioned.

That nonstop code you're talking about is the javascript of the engine itself, not added by the game devs.
 

Satori6

Game Developer
Aug 29, 2023
503
1,113
And when i try to understand the code with my little to no experience with javascript, i see that the same thing can also be achieved through a story format code or HTML itself. Apart from minigames and such, if i can achieve the same thing with say Sugarcube or HTML, is there a technical reason or benefit for using javascript instead?
It depends on what kind of game you want to make.

If it's just an HTML novel where you click text links to change scenes and show some pictures along the way, you only need to know the very basics of TwineScript.

Things like randomly generated NPCs, dynamical event descriptions, minimaps, displaying different outfits over the same character sprite, and other moderately complex mechanics will need JS.

HTML and CSS are just the visuals. Javascript are the instructions.