Forum rules - please read before posting.

Random selection from a decreasing list

edited January 2017 in Technical Q&A
I have a list of places, I want to randomly select a place. Once the interaction in that place is done it will be marked as visited. Then randomly select another place from the list - the place marked as visited, repeat the process until the there is no more places left.

Any suggestions on how to do so?
I can write custom code but would like to avoid that if possible. I searched but didn't find anything related to what I am asking for.

Comments

  • I'd do it this way: First of all you need a variable to count the number of visited places (Count). Then you need a boolean variable for each scene that can be visited. You build an ActionList with a Variable: Check Action first where you check if the Count variable if less then the number of places you can visit. If this is true you start a Variable: Check random number action where you wire up a Variable: Check Action where you test if this scene was already visited (via the boolean variable for each scene). If the place was not visited yet set the apropriate boolean variable to true, increase the count variable by one, visit the place and after that start this ActionList again. Otherwise if the scene was already visited go back to the start of the ActionList. Basically that's what to do. You can quit the ActionList if the Count variable equals the number of visitable (is that a word?) scenes. It would have been easier to create the ActionList in Unity and make a screenshot, but I don't have Unity here right now. Hope what I wrote makes sense.
  • Thanks for your reply.

    So what you are saying 
    if the number of places (5) is bigger than the number of visited places then do the random check even if visited places is 4?

    I kinda did a similar thing.

    but I wanted to avoid doing random when for example number of visited places is 1.
    it will do random more than once till it finds the remaining available room. So once a room has been visited it is removed from list to randomly select from.
  • Maybe the loop is gone through several times while the scenes not visited decrease, but I guess you won't notice it while playing if it loops for maybe 15 times.
  • If I can avoid that it would be nice =)
    thanks for your help and if you ever come up with an idea please share it =)

    one thing that bothers me
    When a room is selected, the npc is supposed to say a line. however, sometimes no line is played?
  • edited February 2017
    I think I found a way
    If the number of visited rooms is 1 or 2 I will do random selection.
    if 3, I will do random selection between 1 and 2. If the result is 1 it will loop from room 1 till room 5, any room it find un-visited it gets select. if the result is 2, it will loop from room 5 till one and select the available room. 

    If I have one available room then I will loop and select that room =)
Sign In or Register to comment.

Howdy, Stranger!

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

Welcome to the official forum for Adventure Creator.