Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Autosaves and more

A topic by greendad37 created May 24, 2022 Views: 191 Replies: 2
Viewing posts 1 to 3

Below are some changes that I have made to the Ramus script file. I've split the file into three files (css, html, js) to make it easier for me to write stories and modified code, but the instructions below should be easy to do to the single combined file.

Added story information to the HTML
<!-- customization-->

<div id="story-name">Ramus Template</div>

<div id="story-version">1.1</div>

<div id="story-author">Some One</div>

Added restart link in the footer in the HTML

<a href="#" onclick="restart(this);">Restart</a>

Added variable in JavaScript - based on story info in html - used for unique save to localStorage

/* customization: get story name from HTML form

*/

var storyName = document.getElementById("story-name").innerHTML;

Add function in JavaScript to load story data - refresh browser will pick up where you left off

/* customization: load storydata from HTML storage

*/

var storage; 

var fail;

var storydata = {};

loadStory();

START = storydata.location;

moves = storydata.moves;

var total = 0;

for (var i in score)

total += score[i];

function loadStory() {

try {

(storage = JSON.parse(localStorage.getItem(storyName)));

fail && (storage=false);

} catch (exception) {}

if (storage) {

storydata=JSON.parse(localStorage.getItem(storyName) );

moves = storydata.moves;

START = storydata.start;

score = storydata.score;

document.getElementById("moves").innerHTML=moves;

}

else {

START="start";

moves=1;

score={};

visited={};

storydata.location=START; 

storydata.moves=moves;

storydata.score=score;

storydata.visited=visited;

localStorage.setItem(storyName, JSON.stringify(storydata));

}

}

Added save function to localStorage in JavaScript

/* customization: save storydata to HTML storage

*/

function saveStory() {

localStorage.setItem(storyName, JSON.stringify(storydata)); 

}

Added restart function in JavaScript - called by link in footer

/* customization: restart the game from link in footer

*/

function restart(node) {

localStorage.clear(storyName);

if (status_line !== null) status_line.innerHTML = "";

if (moves_line !== null) moves_line.innerHTML = "0";

if (score_line !== null) score_line.innerHTML = "0";

transcript.innerHTML = "";

moves = 1;

score = {};

visited = {};

storydata.moves = moves;

storydata.score = score;

storydata.visited = visited;

storydata.location = START;

saveStory();

if (moves_line !== null)

moves_line.innerText = moves;

advanceStory(start);

}

Modified Ramus function advanceStory - add this at the end of the function

/* customization: autosave storydata

*/

storydata.location=fragment.id; storydata.moves=moves; storydata.score=score; storydata.visited=visited; saveStory();

Would it be possible to get your source files for these via pastebin or github?

@boxofcereal - please let me know if you can grab the files off of my repl.it account - index.html - ramus-2.5.1 - Replit