Hello,
I have just joined the Twine forums so please exuse any and all of my stupidity.
I am trying to make a game that has you constantly clicking a link to a passage that increases the value of a variable.
ie.
::menu
Money: $<<print $money>>
[[Make Money|makeMoney]]
::makeMoney :nobr:
<<set $money += 1>>
<<menu>>
This works fine other than having the page refresh every time i click the link. Is there a way I can make a <<button>> that just edits a variable without sending the player to another passage? Thanks for reading this.
Comments
My understanding is that changes to variables are driven by navigation (changing passages). All variable changes within a passage (that aren't assigned to navigation) are executed when the passage is loaded.
My knee-jerk approaches to your problem would be:
- Briefly tweaking the CSS to hide any transition effect, so refreshing is less obvious (not the solution you're seeking, I realize)
OR
- Coding a JavaScript onClick() event, so the change to the variable takes place outside of the passage, strictly speaking. I'm not sure how to write a custom macro offhand, but it's what I'm studying right now, so I hope to understand it soon
If I can be useful, let me know.
I hope this helps.
Is there a way one can make a ink that just edits a variable without sending the player to another passage? Yes. They are called loops. I use a setter-link above, too.
For more information, see my tutorial: How to Create Loops in Twine
Hope that helps!
Or, if you use the SugarCube header, you can just write (in your Menu passage): http://www.motoslave.net/sugarcube/docs/#macros-button
Sharpe -- I'm seeing a [[Make Money|menu][$money += 1]] solution refresh the passage. This seems to be what OP is trying to avoid (although generally making money is refreshing, heh heh.) Let me know if I'm missing something.
Erik -- Holy cats, I didn't realize SugarCube could work this way. Thank you for posting this option. (I also realize now my SugarCube installation was snafued, which probably explains why I don't know things about SugarCube. Here I go to lurk more...)