0 votes
by (120 points)
edited by

Hi! :)

 

I'm using Twine 2 / Sugarcube 2.

 

So I don't know much about coding, but I've been playing around with a game that relies heavily on gathering and swapping items with those items being a big part of what options are available.

 

The problem is all the tutorials I've been using haven't answered one of my crucial questions. How to use all the item variables I've created to display options based on certain items in your inventory.

 

So I have started making a bunch of items as per below:

<<set $inventory = []>>

<<set $toolkit = {
   "name" : "Toolkit",
   "description" : "A small leather toolkit meant for repairing your chemistry tools.",
   "weight" : 5.0,
   "material" : "metal",
   "edible" : false,
   "drinkable" : false,
   "physProtect" : false,
   "elmProtect" : false,
   "flammable" : false,
   "sparkable" : true,
   "weapon" : true,
   "trapPart" : true,
   "repair" : true,
}>>

 

Now I'm aware the below is not code, but I'm drawing a blank as to what to do or even if I'm explaining myself correctly so I thought I'd add it to show what I mean.

You look in your bag for something to throw as a distraction.

<<if any item under "weight" lte 4.0 or "trapPart" = true >> 
[[Attempt distraction by throwing $ITEM]]
repeat for all possible items
remove item from inventory
<</if>>

[[Stay silent and wait for him to move on]]

I guess my questions is is this possible and can anyone link me a tutorial or something that explains how I would do this in very simple terms?

Thanks

 

 

1 Answer

0 votes
by (2.2k points)
edited by

my advice would to be to use a simple if statement, like 

<<if $rock == true>>[[throw rock to distract]]<</if>>

I am very bad at this so there's probably a better way and I probably don't even understand your question. You'd also have to do this for every item that the inventory may contain, so that's a pain.

My bad, I corrected the missing '=', thanks for point that out greyelf and 2, I did not know that, that's pretty handy

by (120 points)
Hey thanks for the comment. Yeah that was the original idea when the game wasn't too inventory-heavy. Now I'm hoping to make some code that reads the current inventory array and provides additional options based on what you have.
by (159k points)

There are two issues with @AnoeticDuckling's <<if>> macro example:

1. The example incorrectly uses a single equals sign operator '=' (which means assignment) when it should be using a double equals sign operator '==' (which means comparison). I suggest using the is operator for comparison instead, as it's harder to get that confused with the assignment to operator.

2. You don't need to use a comparison operator when checking if a variable is equivalent to either true or false.

<<if $variable>>
This message only appears if the variable contains a value equivalent to true.
<</if>>

<<if not $variable>>
This message only appears if the variable contains a value equivalent to false.
<</if>>

 

by (2.2k points)
edited by

Do you mean provides additional things based on what you have like

<<if $hook and $rope>>[[make a grappling hook]]<</if>>

as in if you had a multitude of objects for combinations? I don't personally know of a way to do that besides listing every combination and object yourself, but! I am not even an apprentice level of knowledge on these subjects.

Edit: I had an idea, tie a variable to the process of looking through your inventory and make it display all the available combinations and items you have. Like in a startup passage go through every item and what it can be used for and it's combinations and all that jazz and then assign that all to a variable. then use the variable in a normal passage to display all the options avaliable. Would that be something possible tho?

...