HTML Implement currency/stat tracking in twine 2's sugarcube?

starvoyager

Member
Game Developer
Jul 22, 2017
452
476
I've done some research on this, but i'm not a coder and everything that came up assumed you had at least a few dozen hours of java/html practice. I was able to jury rig one thing in a twine 1 game, but a friend really wanted me to switch to twine 2 (and it does have some benefits), so i'm using that now. What I need is just a way to make a number show up on the left hand side, the ability to make clicking on certain links increase or reduce that number, and the ability to make links that only show up If you have a certain stat. I'd also like to be able to do this with miscellanous things like dick size as well, so on the left it would say
"Money - $100
"Dick size - 5in"
And then based on your action either of those can increase or decrease upon clicking certain passages, and passages don't show up if you don't meet the requirements. I'm not trying to make an open world game with jobs and encounters or anything, just a simple "You read the passage and click A or B to go to a new path, those paths continue until you reach a preexisting ending" and The money/size stuff is just for the player to be aware of, so it doesn't need to be anything advanced. I'm sorry if this has been asked before, but none of the titles of questions seem to be asking this exact thing, they're mostly somewhat related questions that don't really help with this
 

TediousNonsense

New Member
Jan 16, 2021
1
1
You can do this by setting story variables. So for your Money example, when you first give the player money, you would include the set macro:

<<set $money to 100>>

Note that the $ sign here doesn't signify currency, it's just telling Twine that the variable should persist through the story. The name "money" could be anything you want, but it's best to choose things that you'll find easy to remember. The value here doesn't have to be 100, just put it at whatever number you want for their starting cash. 0 or negatives are fine, too.

Then when you want to add money, you can use the set macro with a slightly different command. Say you want to give them $50 in a passage, you'd write:

<<set $money += 50>>

Again, the value can be anything you want. If you want to decrease their money, you can use a negative increment command like:

<<set $money -= 50>>

Finally, to show the current value anywhere in your story, just use print, like so

<<print $money>>

This will only give you the number, so you might want to have some text packed around it, e.g.

Money: $<<print $money>>

Using this macro to manipulate other variables is straightforward enough, so long as you remember to give them separate names ($dicklength, etc.)
 
  • Like
Reactions: starvoyager

starvoyager

Member
Game Developer
Jul 22, 2017
452
476
So I put that at the top of whatever passage I want to have them gain money from, and when they click the passage it's added/lowered at the start of that passage?
I guess my only questions are how do I have things be displayed in that panel tro the left, and how do I have links only be clickable if you meet certain requirements?
 

ExhibitGames

Female Exhibitionist
Game Developer
Nov 10, 2020
35
79
In order to put text into the left sidebar, you have to make a passage called StoryCaption separate from the game passages.
You can then add items, stats, links etc.
 
  • Like
Reactions: starvoyager
Jan 23, 2020
2
2
When you enter a new passage it will execute the code bits it recognizes on the page and run them. There are some things, like inputs (buttons, links et cetera) that will only run when you click on them. If you want to yeet the player to a new passage you can just add money that way. If you're looking to lock off certain choices, you're probably looking for if statements. You can use these to wrap around things, and have requirements that need to be fulfilled before they are executed. This would look like.

<<if $money > 100 >> thing you want to happen <</if>>

Also, I would recommend taking a look at sugarcube's documentation page. It's not the most user friendly, but you can glean some interesting information from it.
 
  • Like
Reactions: starvoyager

starvoyager

Member
Game Developer
Jul 22, 2017
452
476
Thank you guys very much for your help <3 I really appreciate it
There's one other thing but I feel bad about asking so many questions, but if you know off the top of your head and without having to do any effort or anything, I'm curious how you add something to the storycaption after a certainpoint?
Like, money will be there in the beginning, but if there was a different stat that I didn't want to show up until a certain point because it'sonly useful on one route of the game, how would I make something on the storycaptiononly show up after a certain click?

Would it be like, on story caption you put <<If $flag1 checked "Stuff I want to show up>> And then I put $flag1 on the passage I want it to start showing up on?
 
Jan 23, 2020
2
2
Yep, pretty much. You could use a boolean, basically a yes or no. So that would be <<set $variable = true/false>> and then like you said you can have something in an if statement, so <<if $variable == true>> stuff you want shown <</if>>
 
  • Like
Reactions: starvoyager

starvoyager

Member
Game Developer
Jul 22, 2017
452
476
I really appreciate your help.
I'm an at-best-slightly-above-average lewd writer making stories, but after working on a very simple
'Passage of text'
'Do you choose A or B'type game like devious world or any games by lilygames where there's no real open worldness, I enjyoed it and want to make more, but I have next to no programming knowledge, so i appreciate your help.
I think there's something to be said for being able to know for a fact that everytihng abotu your character was in mind whenthe text you're reading was written, andknowing nothing about it was random.
Like in CoC, the game is great, but sometimes the knowledge that the text had to be written to accomodate every character and the occasional disconnectedness can make it feel not as fun.
Sorry about the tangent, my main point is that i really appreciate your help
 

PTSdev

Member
Oct 21, 2019
111
371
Take a look at these guides:
https://f95zone.to/threads/general-guide-to-game-development-and-twine-sugarcube.145013/ (by OnTopOfMyAnger)

https://f95zone.to/threads/getting-the-most-out-of-sugarcube.139958/ (by me, sorry for the shameless plug, but maybe it helps you.)

Some general advice:
If you're not very experienced at coding, start with something small and simple. Try to tackle one problem at a time. Use the Sugarcube documentation and the Twine subreddit, they're really helpful.

Some advice on your questions above:
Changing story variables inside a passage does work, but it can lead to some problems. Story variable changes get stored in the history AFTER a passage transition. If you change a variable with a link / button etc. on a passage, it's not stored yet.

If you have cyclical tasks, e.g. a time system, you can take a look at the PassageReady special passage. Here, you can do calculations BEFORE the passage is being rendered.

Do you want to create some kind of open world / free roam game? I highly recommend using StoryInit to properly define your variables, arrays and objects, e.g. you can create an object containing the game's locations with some properties. Feel free to dm me if you have more questions.
 

starvoyager

Member
Game Developer
Jul 22, 2017
452
476
Do you want to create some kind of open world / free roam game? I highly recommend using StoryInit to properly define your variables, arrays and objects, e.g. you can create an object containing the game's locations with some properties. Feel free to dm me if you have more questions.
Thank you for the advice! I'm more a writer than a game-maker, so If you've played any games by lilygames or if you've played devious world, it's like that.
Simple, hand written "do you choose A or B" CYOAs that eventually lead to endings