HTML Help and tips for twine Sugarcube coding

Drmmrt

Newbie
Jul 14, 2017
81
248
Hey everybody!

Recently I started my first html game with twine (sugarcube 2.3) and been hobbying away for a while.
I've got a decent amount of content, places and a couple of random events but I want to take it a step further.
I am a complete amateur related to coding or twine (like I said, this is the first thing I try) and all I've got so far is with the help of google, youtube, forums and a lot of trail and error.

What I like to add to my game are:
-some first time encounters (you meet a character for the first time and that event doesn't come back again)
-some way of releasing various options with the characters. the way my game is now is more or less like a completed version of the game without any requirements to unlock content.
-and with the options mentioned above maybe some sort of shopping/gift system.

I know these things aren't really original and should be fairly simple (I think), I did look tough the forum (sorry if I missed a thread that already covered this!) but couldn't really find what I was looking for (or missed it because it wasn't what I excepted it to be).

If any of you could and would like to give me some pointers or point me in the right direction, that would be awesome and I would be very grateful! :)
Thanks in advance!
 
  • Thinking Face
Reactions: Cul

givu

Member
Jan 17, 2018
107
259
(First time encounters) I handle it like this:
<<if $charactermet is false or $chartermet is undefined>>
Character introduction scene
<<elseif $charactermet is true>>
Other scene
<</if>>

if you want to use multiple scenes for the same character in the same location, instead of a "false" or "undefined" statement you can use values:
<<if $characterscene is 1 or $characterscene is undefined>>
First scene
<<set $characterscene to $characterscene +1>>
<<elseif $characterscene is 1>>
Second scene
<</if>>

I use t simple "if" statements for almost everything in my game since it´s the easiest way for a beginner i beleieve. Im creating a twine sugarcube atm too with zero prior knowledge. Fell free to contact me if you have other questions!
 

Drmmrt

Newbie
Jul 14, 2017
81
248
(First time encounters) I handle it like this:
<<if $charactermet is false or $chartermet is undefined>>
Character introduction scene
<<elseif $charactermet is true>>
Other scene
<</if>>

if you want to use multiple scenes for the same character in the same location, instead of a "false" or "undefined" statement you can use values:
<<if $characterscene is 1 or $characterscene is undefined>>
First scene
<<set $characterscene to $characterscene +1>>
<<elseif $characterscene is 1>>
Second scene
<</if>>

I use t simple "if" statements for almost everything in my game since it´s the easiest way for a beginner i beleieve. Im creating a twine sugarcube atm too with zero prior knowledge. Fell free to contact me if you have other questions!

Thanks alot! That will help very much!
one followup question though,

do I write the code in a special passage (like the StoryCaption or somthing like that) at the passage with the first encounter scene or in every passage containing that specific character?
 

givu

Member
Jan 17, 2018
107
259
Thanks alot! That will help very much!
one followup question though,

do I write the code in a special passage (like the StoryCaption or somthing like that) at the passage with the first encounter scene or in every passage containing that specific character?
You put it in the same passage where the scene takes place.
<<if $conditionx is x>>
Everything written here will only be displayed if "conditionx" is met
<</if>>

Here is how i did a similar thing:
example.jpg
I wanted the scene to change when the corruption of the character grows. This method can be implemented in a variety of ways.
 

Dungeon Gaming

Member
Game Developer
Feb 22, 2020
168
878
Using If statements, you can set up one time encounters and unlocking new options with characters if conditions are met.

Setting up a inventory system is more tricky, I'd look into different tutorial and guides to find something that fits what you are looking for. I would suggest using Data Structures when setting up different variables about an item. It will look something like this:

<<set $itemname = {
name: "Name",
cost: 10,
description: "Remember to use quotes for strings",
}>>

Then whenever you want to reference any of these variables from the structure, like the cost, just use $itemname.cost.