Howdy, Stranger!

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

Trouble With Variables And Cycling Links

I'm trying to start my game off with what basically amounts to a character selection, but one that is organically integrated into the story. So, using cycling links, I let the player choose the details of the beverage they are drinking/what they are doing at the cafe, and depending on the combination of traits they choose, they'll wind up with one of three characters. The problem is, it isn't keeping track of my variables for some reason. Here's my code:
You find yourself sitting on the patio of a small coffee shop. You have a <<cyclinglink $cupsize "small" "medium" "large">> <<cyclinglink $cupkind "paper cup" "ceramic mug" "teacup">> of <<cyclinglink $cupdrink "hot coffee" "hot chocolate" "hot tea">> in your hands.

[[Take a drink.|Drink]]
<<nobr>>
<<if $cupsize = "small">> <<set $Camron = $Camron + 1>>
<<elseif $cupsize = "medium">> <<set $Zion = $Zion + 1>>
<<elseif $cupsize = "large">> <<set $Lalia = $Lalia +1>> <<endif>>

<<if $cupkind = "paper cup">> <<set $Lalia +=1>>
<<elseif $cupkind = "ceramic mug">> <<set $Camron +=1>>
<<elseif $cupkind = "teacup">> <<set $Zion +=1>> <<endif>>

<<if $cupdrink = "hot coffee">> <<set $Camron +=1>>
<<elseif $cupdrink = "hot chocolate">> <<set $Lalia +=1>>
<<elseif $cupdrink = "hot tea">> <<set $Zion +=1>> <<endif>>
<<endnobr>>
No matter what I set the cycling links to, the amounts of the variables stay the same, and I cannot figure out why.

Comments

  • All your "if $cupsize" need to be "eq" instead of "=". Also, your first three +'s need to be "+=".

    The reason it doesn't work is because the variable isn't set until you go to the next passage.

    Attached is your code fixed.

    Hope that helps! :)
  • Actually the first three +'s will work. But it would be tidier to do it like the +='s further down.
  • No matter what I do, I don't wind up with the results that I should be getting. Putting in 'medium, teacup, hot tea, lost in thought' SHOULD invariably result in getting Zion, but I get Lalia instead. I am completely stumped, here. I've attached my .tws so maybe someone can puzzle out what I'm doing so magnificently wrong?
  • In the begin passage you have this:
    <<cyclinglink $cupsize small medium large>> <<cyclinglink $cupkind "paper cup" "ceramic mug" "teacup">> of <<cyclinglink $cupdrink "hot coffee" "hot chocolate" "hot tea">>
    You're missing quote marks around small, medium and large.

    I do that kind of thing all the time. ;)
  • Also, in the Name2 passage you still have "=" where you need "eq". Twine 1.4.1 allows you to use "is" instead of "eq", which I find helps me remember to put the right one.

    EDIT: Also also, a lot of the time you're doing this:
    <<set $Camron = $Camron += 1>>
    That may or may not work, but it just needs to be:
    <<set $Camron += 1>>
  • Bigger also, the variable "identity" is set to 0 at the start, but then never set again! So when your game checks which character name it contains, it won't be any of them, but the number 0. Was that just an oversight, or do you need help writing the code?
  • It was just an oversight. I've been moving things around so much, the code got accidentally deleted.
    I fixed the other things you said, as well, but now $identity will only return the initial set value of 0 and I have absolutely no idea why.
    I put in a check via the "print" function to see where points are being allocated for the cycling links, and none of those are working the way I intended either. ((I think I might just be terrible at coding))
  • First of all, I told you and also wrote code to show you that your code in Begin needs moved. So, I did that.

    Next, notice I created the new entry titled "Set" with the "nobr" tag. The "nobr" tag removes the need to use "<<nobr>><<endnobr>>" in that passage. You can use "<br>" HTML tags inside such a passage to create white space. Pretty cool, huh? :)

    I also added the "nobr" tag to a couple other places as well as <<set $identity = "Error">> to Start.

    Again, Like I said, the cyclinglink variable must be set in the next passage, so I created a second "Set" passage as well.

    As for the values being equal, I was lazy and just set the conditional branch to "gte" rather than "gt" and then figuring it out after that. I let you mess with that if you want. After reviewing my code, you should be able to do so.

    Seems to work perfectly. I played it about six times all the way through and the results always were what they should be.

    Attached is the TWS and HTML files.

    Hope that helps . . . and I hope you read and follow my instructions and code this time before asking another question. Not trying to brow beat you, but it annoys me when I take the time to write an answer and post a TWS file, and then it gets ignored. Understood? Cool. :)
Sign In or Register to comment.