1) Is it best to have an idea of all game mechanics that I want before beginning or is it best to build the storyline and then come back to fill out the mechanics?
I'd say it's always best to have things figured out ahead of time. So, it's important to decide which is the master: the story or the mechanics?
If the mechanics serve the story, figure out the story first and then build the mechanics to suit it. If the story is built around the mechanics, make sure you have a firm grasp on how you want the mechanics to work before you put too much of it into the story.
If they're separate, and there is no master, I'd say build a good base of code first, since that makes it easier to build the story around that later and then to test how it works as you go. You can always pre-release a partial story with functioning mechanics, and then update as you go. However, it's just frustrating to try to play a game with a good story but non-functional mechanics.
2) For NPCs and Monsters, is it best to have a passage designated to individual NPCs and Monster Types?
That depends on the game. If detailed information is important to the story and interesting to read, then possibly. However, in most cases it's better to show, and not tell. Having the players feel the icy chill and see their breath as they draw closer to the ice dragon's lair is generally far more interesting than saying that ice dragons make the area around them freezing cold.
how could one leave the conversation while keeping all the choices?
You will need to create a variable or variables that you can set "flags" on, to indicate when certain things have happened. For example, I use the following:
In the StoryInit passage I initialize the $Flags variable as an empty object:
<<set $Flags = {}>>
Then I create a "Global Widgets" passage (you could call it anything though) and set the "widget" and "nobr" tags on it, with this code inside:
/* SetFlag : Set Flag X to value Y (Y defaults to True). Flags are not case sensitive. */
/* EXAMPLE: <<SetFlag "Mentor" "Harmony">> */
/* EXAMPLE: <<SetFlag "TrialMed">> = sets TrialMed flag to True */
<<widget "SetFlag">>
<<set _Fnam = $args[0].toLowerCase()>>
<<if def $args[1]>>
<<if $args[1] == false>>
<<if def $Flags[_Fnam]>>
<<run delete $Flags[_Fnam]>>
<</if>>
<<else>>
<<set $Flags[_Fnam] = $args[1]>>
<</if>>
<<else>>
<<set $Flags[_Fnam] = true>>
<</if>>
/* Event flags: */
/* keep track of your event flags here */
<</widget>>
Finally, I put this in the JavaScript section:
/* Flag : If flag exists then return its value, else return false. */
/* EXAMPLE: <<if Flag("Mentor") == "Harmony">>Hello, Harmony.<</if>> */
/* EXAMPLE: <<if Flag("TrialMed")>>You're taking the meds.<</if>> */
window.Flag = function (Fnam) {
if (State.variables.Flags[Fnam.toLowerCase()] !== undefined) {
return State.variables.Flags[Fnam.toLowerCase()];
}
return false;
};
Now I can easily set and check flags as shown in the "EXAMPLE" comments above. If you test Flag() for a flag that doesn't exist, then it will return false.
3) UI Bar - Is it possible to add a character page, inventory, and equipment to the UI bar?
Yes, the StoryCaption passage is where this is commonly done.
4) With character inventory, I plan to have creatures and stuff that they can get but I do not know how to make the system give a different key for same items.
For something like this it's better to use objects, like $Flags does above.
You can have an object called $inventory, and then add other objects to it which each have their own properties. A simple example:
<<nobr>>
/* Create an empty inventory. */
<<set $inventory = {}>>
/* Add 5 pieces of iron ore worth 20 gold each to the inventory. */
<<set $inventory.IronOre = { name: "iron ore", quantity: 5, value: 20 }>>
/* Add 5 more. */
<<set $inventory.IronOre.quantity += 5>>
/* Check to see if you have copper ore. */
<<if def $inventory.CopperOre>>
You have $inventory.CopperOre.quantity $inventory.CopperOre.name.<br>
<<else>>
You have no copper ore.<br>
<</if>>
/* Add 1 piece of steel worth 50 gold each to the inventory. */
<<set $inventory.Steel = { name: "steel", quantity: 1, value: 50 }>>
/* Display the inventory. */
<<for _key range $inventory>>
_key.quantity _key.name worth _key.value gold each.<br>
<</for>>
/* Three different ways to show the same value. */
<<set _temp = "IronOre">>
$inventory.IronOre.quantity = $inventory["IronOre"].quantity = $inventory[_temp].quantity<br>
/* Get an array of all inventory keys and display it. */
<<set _keys = Object.keys($inventory)>>_keys
/* Get rid of the steel. */
<<run delete $inventory.Steel>>
<</nobr>>
So, that's a basic rundown of the methods you'd need to know to manipulate an inventory like that. You don't have to use "name", "quantity", or "value", and you can have as many other properties as you want (though less is better, since that means it takes up less memory, which may be a limited resource), each with whatever values you want. To keep things simple, don't start property names with a number and don't put spaces in them. (Also, see the <<for>> macro for details on how it lists through objects.)
If you're interested, I'm working on a Twine 2/SugarCube 2 inventory "plugin" to make working with inventories simpler. It's called the "Universal Inventory System", or "UInv" for short. It's still in pre-release (so the full release may break pre-release code), but you can check out the UInv help file online if you'd like to take a look at it. Or you can download UInv v0.9.5 from this temporary link (link expires 8/15/'18).
Hope that helps!