Howdy, Stranger!

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

Creating an Inventory

I am just starting out on Twine and am starting to feel like I'm getting the hang of it, but I want to go beyond just a simple choose-your-own-adventure game. Creating an in-game inventory feels like it would be a good starting point, but I know nothing about coding and any explanations that I find online are right on the border between understandable English and CSS gibberish.
Assuming I know little to nothing about coding, how would I go about making a simple inventory? (i.e., containing quest items and miscellaneous garbage). And on a similar note, how could I make a record of the player's stats in the game? Would the two concepts be alike in how they're done?
Again, this is assuming that I know nothing about coding and that I'm only just starting to learn how to do it correctly.

Comments

  • As suggested in this topic you may want to read this article.
  • Is there any place where something like this is explained in a tutorial? Or could someone just flat-out spell it out for me in the layman's terms
  • You can use variables to track what is happening in your game. This can be anything from how much health the player has to whether the player has found the Dagger of Doom yet. As the Twine Wiki link explains you use the <<set>> macro to assign a value to a variable.

    Following is an example of assigning some variables and then using those variables in your game.
    (note: The first four lines that start with the <<set>> macro should be added to your games StoryInit passage, the last two lines could be added to your Start passage.)

    <<set $my_health to 100>>
    <<set $my_colour to "Grey">>
    <<set $my_race to "Elf">>
    <<set $has_doom_dagger to false>>


    My name is <<print $my_colour + $my_race>>, my health is currently at <<print $my_health>>%
    I <<if $has_doom_dagger>>have<<else>>have not<<endif>> found the Dagger of Doom.
    What sort of inventory system are you looking for?
    If you only want to track if the player has found selected items then you can use simple variables like the example above to achieve this. Just use the above as a starting point and extending it by adding more variables as needed to track whatever you want.

    The Twine story formats are designed to create Interactive Fiction (IF) and Choose Your On Adventure (CYOA) type games.

    You can create a Role Playing Game (or most other games types) with it but features like Combat, Inventory, Shops, Clothing (Armour), and the like are not built-in and you will have to do most of the hard work to implement them.
  • Yes, I'm just trying to implement a simple inventory. I think anything more complex than that would be too much for me to attempt. This is exactly what I need to get started.
    And I haven't tried it yet, but would this code work in the 2.0 beta? Or is it still too rough? I know I haven't seen anything about using CSS in the beta anywhere, so I'm assuming either it doesn't work yet or no one's written anything about it.
  • Amyphere wrote:

    And I haven't tried it yet, but would this code work in the 2.0 beta? Or is it still too rough?

    Both the format of a macro (<<macro_name>>) and what macros are available are control by the story format you select when building your game/story, and currently the 2.0 beta version of Twine does NOT support the older story formats that are used by Twine 1.x, so you cant copy code from a 1.x project over to a 2.0 one.

    The same code using the 2.0 beta and the Harlowe story format would look like the following:

    (set: $my_health to 100)
    (set: $my_colour to "Grey")
    (set: $my_race to "Elf")
    (set: $has_doom_dagger to false)


    My name is $my_colour$my_race, my health is currently at $my_health%
    I (if: $has_doom_dagger)[have](else:)[have not] found the Dagger of Doom.
    Amyphere wrote:

    I know I haven't seen anything about using CSS in the beta anywhere, so I'm assuming either it doesn't work yet or no one's written anything about it.

    The 2.0 beta supports CSS but it is different than 1.x in two major ways:
    1. There is a special passage where all CSS must be places.
    2. The structure of the HTML file generated by the Harlowe story format is different than the older story formats and the elements of the parts of that structure have different id/names than before, so the selectors of the CSS you write are different than the ones used in 1.x.

    The Harlowe story format also has its only built-in macros which you can use to formatting the text of your story.
  • [quote]

    (set: $my_health to 100)
    (set: $my_colour to "Grey")
    (set: $my_race to "Elf")
    (set: $has_doom_dagger to false)

    My name is $my_colour$my_race, my health is currently at $my_health%
    I (if: $has_doom_dagger)[have](else:)[have not] found the Dagger of Doom.
    So if the format of the code in the two versions are different, would I be able to implement 1.x code in a 2.0 project by changing some of the syntax and changing the double angle brackets (<) to a single parenthesis? Only in the case of the examples.
  • Partly, it depends on which macro.

    It would work for some macros like set

    Sugarcane: <<set $variable to "value">>
    Harlowe: (set: $variable to "value")
    but would not work as well for macros like if / if else

    Sugarcane: <<if $variable is "value">>The variable equaled the value<<endif>>
    Harlowe: (if: $variable is "value")[The variable equaled the value]

    or

    Sugarcane: <<if $variable is "value">>The variable equaled the value<<else>>The variable was NOT equal the value<<endif>>
    Harlowe: (if: $variable is "value")[The variable equaled the value] (else:)[The variable was NOT equal the value]
    Array initialization, assignment, manipulation and referencing is different between Harlowe and the Twine 1.x story formats, and Harlowe also has a number of new built-in macros.

    Also Twine 2.0 and the Harlowe story format are both beta projects, so may change without notice and these changes may break your story/game.
Sign In or Register to comment.