Howdy, Stranger!

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

Help displaying a dynamic list on a page

Okay, I give up.

I've got a group of characters and a list of locations. Based on how far my players have progressed with each character's plot, each character could be in a different place, and who the character may have to visit to continue a specific character's plot may change.

I am trying to build something that will generate this list automatically. Each location could either be empty, have a character present, and talking to that character would progress THAT character's plot, or have a character present, and talking to that character would progress ANOTHER character's plot.

Right now, what I have is a whole ugly mess of if statements that is horrible to work with. Ideally what I would like is something where I can put the plot states in one place and have a widget or something refer to that to see who is where when as it builds the list, but I have no idea how to do that. I've been playing around with various ways to do this, but I haven't found a solution that works. I can finagle something, but it always seems to end up being if/then statements somewhere instead of a clean loop referencing something like an array.

I can provide code when I'm not about to run out the door if anyone has suggestions or questions.

Thanks in advance!

Comments

  • edited April 2017
    You probably should be using an array, as you mentioned (sort of). Without more info, I can't comment on specifics, but it might be wise to make an array for each area and then pluck or push the characters in and out of the arrays based on where you need them.

    I didn't test the code below, so it's probably rife with errors, but it's just an example of how something like this might be done:
    ::somewhere in your story
    <<set $mall to []>>
    
    <<set $sally to {
       link: "Talk to Sally",
       passage: "sallyTalk",
       progress: 0,
       return: "mall"
      }>>
    
    /%sally is at the mall if you're progress in her storyline is 0%/
    
    <<set $mall to $mall.push($sally)>>
    
    ::mall
    You're at the mall. 
    
    <<if $mall.length>>\
      <<for _i to 0; _i lt $mall.length; _i++>>
       <<link $mall[_i].link $mall[_i].passage>><</link>>
      <</for>>
    <<else>>\
    You don't see anyone you know. 
    <</if>>
    
    ::sallyTalk
    <<if $sally.progess is 0>>\
    Hello! 
    
    /%change $sally variables%/
    <<else>>\
    Other stuff. 
    
    /%change $sally variables%/
    [[Leave|$sally.return]]
    
  • edited April 2017
    I tested it and I indeed made some errors:
    ::somewhere in your story
    <<set $mall to []>>
    
    <<set $sally to {
       link: "Talk to Sally",
       passage: "sallyTalk",
       progress: 0,
       return: "mall"
      }>>
    
    /%sally is at the mall if you're progress in her storyline is 0%/
    
    /%THIS IS WRONG: <<set $mall to $mall.push($sally)>> -- it should be:%/ <<set $mall.push($sally)>>
    

    And:
    ::sallyTalk
    /%I MISSPELLED "progress" HERE%/ <<if $sally.progress is 0>>\
    Hello! 
    
    /%change $sally variables%/
    <<else>>\
    Other stuff. 
    
    /%change $sally variables%/
    /%I MISSED A CLOSING TAG:  %/ <</if>>
    [[Leave|$sally.return]]
    

    Note that whenever you change the $sally variables, you'll need to remove and re-add the object to the array again.
  • So what I'm trying to do essentially is generate a "world map" that looks similar to this:

    Location 1

    Location 2

    Location 3

    Each location links to its own page, where the player interacts with characters and advances plots. (Each character is set up as an object that keeps track of, among other things, how far along the plotline the player has advanced.) Since the player always returns to the world map, I want that map to have some kind of notation on it showing who is where and what plotline advances when the player talks to which character. So instead of the basic list above, the world map looks something like this:


    Location 1
    Chief is here
    Advance the Chief's plot

    Location 2

    Location 3
    Apprentice is here
    Advance the Herbalist's plot

    However, since the world map changes every time a plot is updated, I'd like to generate that dynamically. So maybe after talking to the Apprentice at Location 3, the next time the player comes back to the map, it looks like this:

    Location 1
    Chief is here
    Advance the Chief's plot

    Location 2
    Herbalist is here
    Advance the Herbalist's plot

    Location 3

    But so far, other than manually checking a lot of if statements, I haven't been able to figure out a good way to do it. An example below is from one of the widgets I'm currently using
    <<if $loc == "lh">>\
    	<<if $chief.plot == 1 || $chief.plot == 2 || $chief.plot == 3 || $chief.plot == 4 || chief.plot == 6>>\
    		<<set $chief.present = 1>>\
    		<<set $chief.flag = 1>>\
    <</if>>\
    
    <<if $loc == "sq">>\
    	<<if chief.plot == 5>>\
    	<<set $chief.flag = 1>>\
    <</if>>\
    
    <<if $loc == "sq">>\
    	<<if $herb.plot == 1 || $herb.plot == 6 || $appren.plot == 4>>\
    		<<set $herb.present = 1>>\
    	<</if>>\
    	<<if $herb.plot == 1 || $herb.plot == 6 || $herb.plot == 5>>\
    		<<set $herb.flag = 1>>\
    	<</if>>\
    <</if>>\
    
    <<if $herb.plot == 2 || $herb.plot == 3>>\
    	<<set $herb.present = 1>>\
    	<<set $herb.flag = 1>>\
    <</if>>
    
    <<if $loc == "hw">>
    	<<if $herb.plot == 4>>
    		<<set $herb.present = 1>>\
    		<<set $herb.flag = 1>>\
    <</if>>\
    

    etc. This gets REALLY cumbersome to work with, and I would really like to find a better way.
  • I found a mostly workable solution.
Sign In or Register to comment.