added inventory script
This commit is contained in:
parent
25dbbf8b1d
commit
74e1e7d541
2 changed files with 195 additions and 0 deletions
2
contributed/simple inventory/README.md
Normal file
2
contributed/simple inventory/README.md
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
Write PUT THING in a sentence to put THING into your inventory.Write GET and THING in a sentence to GET THING out of your inventory. If you are trying to GET an item not in your inventory you will be informed about it.
|
||||||
|
Example: "You PUT the BOOK into the bag"
|
193
contributed/simple inventory/inputscript.txt
Normal file
193
contributed/simple inventory/inputscript.txt
Normal file
|
@ -0,0 +1,193 @@
|
||||||
|
|
||||||
|
|
||||||
|
const modifier = (text) => {
|
||||||
|
|
||||||
|
|
||||||
|
var found = []
|
||||||
|
|
||||||
|
function isIn(what, where) {
|
||||||
|
if (where.indexOf(what) > -1) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
function arrayIsEmpty(array) {
|
||||||
|
//If it's not an array, return TRUE.
|
||||||
|
if (!Array.isArray(array)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
//If it is an array, check its length property
|
||||||
|
if (array.length == 0) {
|
||||||
|
//Return TRUE if the array is empty
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
//Otherwise, return FALSE.
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
//console.log(text)
|
||||||
|
|
||||||
|
//var modifiedText = text
|
||||||
|
state.modtext = modifiedText
|
||||||
|
//console.log(modifiedText)
|
||||||
|
|
||||||
|
if (typeof(state.bag) == "undefined") {
|
||||||
|
state.bag = []
|
||||||
|
}
|
||||||
|
|
||||||
|
function putBag(what) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
state.bag.push(what)
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkBag(what) {
|
||||||
|
|
||||||
|
|
||||||
|
// console.log("check")
|
||||||
|
// console.log(state.bag)
|
||||||
|
for (thing of state.bag) {
|
||||||
|
if (what == thing) {
|
||||||
|
|
||||||
|
//state.message = "check true"
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
modifiedText = text + " or at least you try but you don´t have it. You may have lost it or just forgotten to take it with you."
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function remBag(what) {
|
||||||
|
|
||||||
|
console.log("rem")
|
||||||
|
|
||||||
|
if (checkBag(what) == true) {
|
||||||
|
|
||||||
|
|
||||||
|
state.bag.splice(state.bag.indexOf(what), 1)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function thingfilter() {
|
||||||
|
function isUpperCase(str) {
|
||||||
|
return str === str.toUpperCase()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wordsplit = modifiedText.split(" ")
|
||||||
|
|
||||||
|
for (word of wordsplit) {
|
||||||
|
if (isUpperCase(word)) {
|
||||||
|
found.push(word)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arrayIsEmpty(found) == false) {
|
||||||
|
return found
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (thingfilter() != false) {
|
||||||
|
|
||||||
|
|
||||||
|
if (modifiedText.indexOf("PUT") > -1 || modifiedText.indexOf("gET") > -1){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
putBag(found[found.indexOf("PUT") + 1])
|
||||||
|
|
||||||
|
}
|
||||||
|
if ( modifiedText.indexOf("GET") > -1 || modifiedText.indexOf("gET") > -1 ) {
|
||||||
|
|
||||||
|
|
||||||
|
remBag(found[found.indexOf("GET") + 1])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var inBagNow = "Inventory: "
|
||||||
|
|
||||||
|
if (state.bag.length > 0) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for(thing of state.bag) {
|
||||||
|
|
||||||
|
inBagNow = inBagNow + thing + " | "
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inBagNow != "Inventory: ") {
|
||||||
|
|
||||||
|
state.message = inBagNow
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
wordsplit = modifiedText.split(" ")
|
||||||
|
|
||||||
|
newstring = ""
|
||||||
|
|
||||||
|
function isUpperCase(str) {
|
||||||
|
return str === str.toUpperCase()
|
||||||
|
}
|
||||||
|
|
||||||
|
for (word of wordsplit) {
|
||||||
|
if (word == "PUT" || word == "pUT") {
|
||||||
|
|
||||||
|
newstring = newstring + "put"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (word == "GET" || word == "gET") {
|
||||||
|
|
||||||
|
newstring = newstring + "get"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (isUpperCase(word)) {
|
||||||
|
|
||||||
|
newstring = newstring + word.toLowerCase() + " "
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
|
||||||
|
newstring = newstring + " " + word + " "
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
newstring = newstring[0].toUpperCase() + newstring.substring(1)
|
||||||
|
|
||||||
|
modifiedText = newstring
|
||||||
|
|
||||||
|
return {
|
||||||
|
text: modifiedText
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't modify this part
|
||||||
|
modifier(text)
|
Reference in a new issue