0 votes
asked ago by (170 points)

I'm trying to make a passage that allows the player to distribute some statpoints among some of the players stats. I'm trying to do this by having some [-][+] <<click>> buttons next to the stat.

Here is some of my code:

Now you can adjust some of your basic attributes.

You have $statpoints stat points left.

Strength: $player.str <<click "[-]">> <<set $player.str -= 1>> <<set $statpoints += 1>> <</click>> <<click "[+]">> <<set $player.str += 1>> <<set $statpoints -= 1>> <</click>>

My problem is that when I click on the [-][+], my displayed stats on the passage don't change;

You have $statpoints stat points left.

and

Strength: $player.str

go unchanged. Any help would be greatly appreciated.

2 Answers

+1 vote
answered ago by (1k points)
selected ago by
 
Best answer

This is a live example from the cookbook (which I have found to be invaluable). I think it does EXACTLY what you want.

 

For example it also adds in an element you have not shown:

<<replace "#intelligenceStat">><<print $intelligence>><</replace>>

<<replace "#pointsStat">><<print $totalPoints>><</replace>>

 

commented ago by (170 points)

This is exactly what I was looking for. I knew I had seen this example before but when i was googling my question, I couldn't find it again.

Just a quick follow up though on the replace macro you used. Could the code also be used like this?

<<replace "#intelligenceStat">> $intelligence <</replace>>

Also, i noticed that in the replace you have #intelligenceStat. I'm very new to using twine so I dont understand when you would choose to use #.

So I'm wondering if for my specific code, would I have to write it like this?

<<replace "#player.strStat">><<print $player.str>><</replace>>

I noticed that at the bottom of the example, <span> is used.

Intelligence: <span id="intelligenceStat">10</span>

Is this what would set up, in my case, the #player.strStat? And is <span> HTML? I have a beginnner understanding of coding laguages so sorry if these are basic questions.

commented ago by (1k points)

Sorry for the delay... I have been swamped. But yes you are on the right track. The variables do need to be changed to match yours. The reason the one I showed you had it listed as "intelligenceStat" is because that is what was written in the cookbook.

I don't know if you went to see the working example provided there. I would recommend it for a few reasons:

  1. You can be sure this is what you want by watching the results as you test it
  2. Further explanations are there for when you need to better understand it
  3. The full code is there (which may be needed if something is to be placed inside the JS or CSS for example)
  4. Other great packages are there (well ... they're not packages per se, I just can't think of a better word at the moment--they are like.... tricks? ideas? anyway...)
  5. There are a variety of these for even for different Story Formats
  6. Twee code is just... um... valuable! to see an overview of what is going on.

Do these make sense?

+1 vote
answered ago by (55.2k points)

I would recommend installing the numberpool macro set, which can be found on SugarCube's site under the addons section. It includes instructions. 

commented ago by (170 points)
Thank you for posting this. I was unaware Sugarcube had addons. At the moment, i'm just a beginner and have a basic understanding of coding language. I hope that eventually I can use these macro sets, but at this time, I do not understand how I could utilize this in my code. I would probably have to change a lot of my player variables.
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...