Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

help!

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

  • I'm a n00b myself, so I hope I don't lead you astray...

    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.
  • EliteZ129 wrote:

    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.


    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.
    ::menu

    Money: $<<print $money>>

    [[Make Money|menu][$money += 1]]
    I use a setter-link above, too.

    For more information, see my tutorial: How to Create Loops in Twine

    Hope that helps! :)
  • Sharpe wrote:


    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.

    Or, if you use the SugarCube header, you can just write (in your Menu passage):
    <<button>><<set $money += 1>><</button>>
    http://www.motoslave.net/sugarcube/docs/#macros-button

  • Ah, these are two interesting options.

    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...)
Sign In or Register to comment.