Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Simple Question From A (Somewhat) Intermediate Twine User

So, I've been using Twine for a while now, and have gained a basic knowledge and fundamental understanding of JavaScript. Having said that, I don't think I'm in anyway a genius and I have a pretty basic question, that probably has a very basic answer.

What I'd like to do that would make coding my story a lot easier is to sort of define specific links to specific objects. What I've been trying to do is build a sort of "Inventory" framework, capable of removing Items from one container and pushing them into another and vice versa.

I've accomplished this luckily, and have the foundations working. (I do so by adding some new methods to the array prototype, I know that it's not good form, but I don't know how else to do it).

But right now, what would make my life a lot easier is to bind clickable links so certain items, so that when I'm sorting through an Inventory, and examine the items therein, it will show a list of clickable links for that specific item that perform specif functions when clicked.

Before I get to ahead of myself, what I'm doing with the "Items" is created an "Item" prototype, and use the prototypal inheritance to specify the different types of Items, for example, Food, Weapons, Armor and so on.

So, my question is, how would I go about adding specif actions to specific types of Items? Ergo Food - Eat, Weapon - Equip. I can do this with Twines if else, but obviously this gets ridiculously obtuse, and honestly, not even doable. I've tried just adding a string to run the macro, and print that but that gets mucky as well.

Any advice would be appreciated.

Comments

  • Assuming you're using SugarCube (not sure this works with the vanilla headers): how about something like:

    <<if $item.action.canDo() eq true>>
    <<click $item.action.name>
    <<set $item.action.doAction()>>
    <</click>>
    <<else>>
    <<print $item.action.cannotDo>>
    <<endif>>

    canDo would check if you can do whatever you're trying to do and return true or false. doAction would have to do all the UI updates, call whatever functions it has to. If you need multiple actions per item, turn $item.action into an array and loop through its members.

    I'm not sure this is really what you're looking for but it's the simplest solution that came to mind.
  • You may want to read the following thread if you are going to use java-script objects with methods, especially the two posts by TheMadExile about Serialization.
  • @EcnelOvelam:
    It's probably just my dotage showing, but I'm not certain exactly what you're looking for (I get the general thrust, but beyond that).  Additional details/examples would help.


    MoLoLu wrote:

    <<if $item.action.canDo() eq true>>


    Performing a conditional test against a boolean primitive is redundant.  Instead, simply use:

    <<if $item.action.canDo()>>
Sign In or Register to comment.