Skip to content
Jonathan Chan edited this page Apr 12, 2024 · 5 revisions

Twine does not support multiplayer by default. Theyr is an addon that allows multiple players to sync up their game states.

Webstack.js

Contains code for syncing up users' gamestates together

Sockets

To ensure users' game states are synced, sockets are used to broadcast one player's new game state to all others.

Routes:

  • difference: the signify a player has set a variable in the game state, will broadcast the difference to all other users
  • fullReset: To fully reset the game for all users

Shutdown

Webstack runs additional code whenever the game is shutdown. This is to preserve a backup of the game's state to restore the game to the last played state when restarting.

Runs code from GitApiIO.js on startup, and shutdown.

GitApiIO.js

GitApiIO.js takes a github repo url, a github authentication token, a json file name, and a json. It has three methods:

  • setupFileApi: creates a new json file on the repo to store the current game state
  • retrieveFileApi: Retrieves the game state store on the json file in the repo
    • initVar.json: If the repo does not contain an existing game state, the game state will be pulled from this file instead
  • uploadFileApi: updates the game state stored on the repo

Client.js

Contains code intended to run in tandem with the webpage produced by Twine

Proxy

A proxy is used to detect every time a user makes a change to their game state. It will then send out a message to all other players alerting them of the change.

Set Up

Upon Twine initalizing in the initTwine() section of Aztec.twee, Sugarcube.state.varibles is replaced with a proxy of itself. This makes it so that whenever a varibale is Sugarcube.State.varibles is changed, the coed in createHandler() is run instead of just setting or getting the variable.

createHandler()

This function is used to create the proxy the system is based on.

  • Set: Whenever a variable is set, it's full path will be found. This path will be used to post a message to other users about the update.
  • Get: Will return part of its path for set's use

TheyrException

<<TheyrException _varName>> is a macro used to set a varibale as a TheyrException. This means that even if a user modfies the given variable, it will not be transmitted to other users. Use this for sensitive data.

init()

Produces the blur effect at the start of the game

changeStats()

Used to create stat setting widgets

LoginDiscord/Index.js

Creates an instance of Webstack.js and starts hosting

Heroku

Starts running index.js, uses environment variables and saves game state on github

Local

Starts running index.js, uses config.json as environment variables, and saves game state on loginDiscord/testVars.json

  • TweeGaze.js Used to restart twine automatically whenever a file is updated. For testing locally

Clone this wiki locally