Quantcast
Channel: Help! with 2.0 - Twine Forum
Viewing all articles
Browse latest Browse all 1844

How to make 'add inventory' macros support multiple inventories?&Other questions(SugarcubeTwine2)

$
0
0
Here is my story javascript(it's the tutorial script):

window.getInv = function() {
return state.active.variables.inventory;
}
macros.initInv = {
handler: function(place, macroName, params, parser) {
state.active.variables.inventory = [];
}
};
macros.addToInv = {
handler: function(place, macroName, params, parser) {
if (params.length == 0) {
throwError(place, "<<" + macroName + ">>: no parameters given");
return;
}
if (state.active.variables.inventory.indexOf(params[0]) == -1) {
state.active.variables.inventory.push(params[0]);
}
}
};
macros.removeFromInv = {
handler: function(place, macroName, params, parser) {
if (params.length == 0) {
throwError(place, "<<" + macroName + ">>: no parameters given");
return;
}
var index = state.active.variables.inventory.indexOf(params[0]);
if (index != -1) {
state.active.variables.inventory.splice(index, 1);
}
}
};
macros.inv = {
handler: function(place, macroName, params, parser) {
if (state.active.variables.inventory.length == 0) {
new Wikifier(place, 'nothing');
} else {
new Wikifier(place, state.active.variables.inventory.join(','));
}
}
};
macros.invWithLinks = {
handler: function(place, macroName, params, parser) {
if (state.active.variables.inventory.length == 0) {
new Wikifier(place, 'nothing');
} else {
new Wikifier(place, '[]<br>[]');
}
}
};
macros.emptyInv = {
handler: function(place, macroName, params, parser) {
state.active.variables.inventory = []
}
};

StoryInit: <<initinv>>

[[Backpack]]: <<if $inventory.length == 0>>You are have nothing.<<else>>You are carrying:
<<inv>> <<endif>>

What do I do if I want to have <<usagethings>> that drop things into certain inventories? For example, on the Sidebar is a [[Journal]] link, that goes to a passage w/: [[Entries]], [[Photos]], [[Evidence]] & [[Objectives]] on it, I want to be able to have the note player found go into the [[Evidence]] inv instead of the [[Backpack]] when picked up &can I label them like: <<addToInv1>> or <<addToInv2>>? Is it possible to get this without re-writing/pasting the macros for each individual inventory?

Another inventory-related question: I have gotten the "add an inventory" tutorial script to work, but how do I make the listing drop down another line for every item? Instead of eventually developing into a long block of text? I've tried adding bullet pts. to the <<addToInv "a thing">> but after the first object added, it starts showing up as an actual asterisk, regardless of whether between "" when I want mult. words or single word additions or not.
I keep ending up w/ this:
(e.g. Backpack:
-spork, spoon)

When I want it to look like this:
(e.g. Backpack:
-spork
-spoon
-etcetera)

Viewing all articles
Browse latest Browse all 1844

Trending Articles