Howdy, Stranger!

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

Explicitly set the visited() variable?

Can I do this?

I'm trying to, like so:
<<set visited("The front yard")=1>>
...but it throws an error: bad expression: invalid assignment left-hand side

?

Comments

  • You use the visited function to ask the game engine if the player has visited a passage before.

    <<if visited("The front yard") == 1>>
    You have been here before
    <<endif>>
    The error occurs in your example because you are trying to assign a value to the function. (the single equals sign means assignment)
  • I want to assign a value to the function because I am using <<display>> to print a passage, which doesn't change the passage's visited value. However, the passage uses conditional text based on the passage's visited value (as in your example).

    I have a workaround in place using a variable instead of the visited function, but I'd been trying to move away from using variables to track visited since this is the purpose of the visited function, and it involves less code.

    I realize this morning that I should be using "+=", not "=". But regardless, it doesn't work. So my question is, is there a way to assign a value to visited?
  • Visited() walks through the history of passages rendered (though, not the ones that are <<print>>ed or <<display>>ed.

    To work around this, you should set a variable in the passage you are displaying, and then check that variable instead of using visited
  • Darnit. Seems strange you can't manually "extend" the functionality of visited. It's great that it keeps count of the number of times a passage is visited, but it's a bummer that you can't manually increase or decrease the value when you know that it should be increased or decreased by dint of <<display>>ing a passage. Thanks though.

    Edit: It makes sense, actually. You shouldn't be able to play with something that has a very specific definition. I guess a way to still make visited() useful when <<display>>ing a passage would be something like:
    <<set $my_own_visited_variable=visited("The front yard")+=1>>
  • The engine does not actually keep track of the number of times you visited each passage as such.

    Each time you change from one passage to another a copy of the current state  (think information about the passage you are leaving and the current value of all variables, but it is more that that) is added to the end of a historical list.
    This list is used for many things, one important one is to track your path through the story which allows you to backtrack if needed.

    What visited() does is look though the history list, counting the number of times it finds a passage with the name your looking for.
  • Pretty easy to write your own counter...
    ::setup
    <<set $beenthere to {}>>
    Then when you want to up the visit count a room :
    <<set $beenthere["room name"] += 1>>
    You can write checks by accessing the value directly:
    <<if $beenthere["room"] gte 5>>...<<endif>>
  • Have you considered visitedTag? This is similar, but counts how many times the player has visited a page with the given tag, so you can have multiple pages counting to the total.
  • Hmm, you know, that would probably do it. I hadn't thought about visitedTag in that way, but yeah, that makes sense. I'll have to look into it and see if it saves a little bit of code. Thanks!
Sign In or Register to comment.