diff --git a/examples/deathIsland.js b/examples/deathIsland.js new file mode 100644 index 0000000..752e7e8 --- /dev/null +++ b/examples/deathIsland.js @@ -0,0 +1,64 @@ + +// Checkout the repo examples to get an idea of other ways you can use scripting +// https://github.com/AIDungeon/Scripting/blob/master/examples + +const modifier = (text) => { + let modifiedText = text + + if(!state.events){ + state.turn = 0 + state.events = [ + 'You hear a rustling in the bushes near you. Suddenly', + 'An ear splitting scream suddenly echoes', + 'You feel a cold chill go up your spine. You look up and see', + 'You suddenly get hit by', + 'Before you can do that you hear a loud crash. You look towards the sound and see a dark demonic looking creature', + 'You discover a horrifying', + 'You hear a terrifying sound', + 'You wake up and realize you were dreaming. You look down and see that your arms are in shackles', + 'A hand grabs your leg and you trip hitting your head on a stone. You wake up in a cage', + 'An uneasy feeling begins to settle in your stomach as', + 'You remember a dark feeling from last night', + 'Suddenly a bloody head rolls toward you from out of the bushes', + 'You see a massive creature', + 'A band of cannibals', + 'You see a band of cannibals', + 'A dark creature', + 'You feel a sharp pain in your side and realize' + ] + } + else{ + modifiedText = "\n>You try to " + text.substring(7) + '\n' + } + + state.turn = state.turn + 1 + + state.message = "You have survived " + state.turn + ' turns.' + + if(state.turn > 2){ + state.memory = {frontMemory: "You're probably going to die."} + } + if(state.turn > 6){ + state.memory = {context: "You're about to die."} + } + else if(state.turn > 10){ + state.memory = {context: "You have no hope. There are minutes left till you die."} + } + + const nTurn = Math.floor((Math.random() * 2)) + 2 + + if(state.turn % nTurn === 0){ + const eventInd = Math.floor((Math.random() * state.events.length)); + if(eventInd < state.events.length){ + modifiedText = modifiedText + state.events[eventInd] + state.events.splice(eventInd) + } + } + + + // You must return an object with the text property defined. + return {text: modifiedText} +} + +// Don't modify this part +modifier(text)