How to make changes to one of several agents without others reacting.

edited June 2015 in Questions about Code

m

Tagged:

Answers

  • the fases are global vars

    but you want to have them in the class Agent / People instead

    so when you loop over the persons say

    if (p.FASE0== true) {
    
    }
     else if  (p.FASE1== true) {
    

    etc.

    also, remember if (p.FASE0== true) { can be written as if (p.FASE0) {

    ;-)

  • since only one of FASE0, FASE1, FASE2 can be true you might as well say

    int fase = 0; and this can be 0,1 or 2....

    and then

    switch(fase) {
    
    case 0: .....
    break;
    
    etc. 
    
    1. This doesn't belong to "Programming Questions", moved.
    2. Learn to format code: How to format code and text and post textual code, instead of image of code: we cannot copy and paste this code in a PDE, and it is not searchable.
  • edited June 2015

    m

  • edited June 2015

    m

  • edited June 2015

    m

  • so 'a' makes the fire start?

  • edited May 2015

    the idea is to handle it for each person individually

    so make FASE2 part of the class People

     for(int i = 0; i < amountOfPeople; i++) {
          People currPeople = persons.get(i);
          if(currPeople.location.y <= -L/2 + 15 ) {
            FASE0 = false;
            FASE1 = false; 
            currPeople.FASE2 = true;
          }
    

    no FASE2 in the sketch, only in the class!!!!!!!!!!!

  • That's correct, when you press 'a' the people will start to 'panic' and a fire will start somewhere. Okay I'll try that first, thanks!

  • you wrote:

    The problem is that when one of the agents (5 in my example) reaches the door and wants to go to his next phase to search for the exit, all the other agents act like they found the door too.

    that's because you store the info (found the door) in the sketch and not for each person individually (in the class)

    ;-)

  • currPeople.FASE2 = true; cannot be resolved or is not a field is my error... Maybe chat is easier for this conversation?

  • did you put FASE2 in the class

    and removed from the sketch...?

  • I'm sorry how do you do that. I'll have to take the variable to my room-class or?

    A little resume to check if I properly understand all your help: Fase0 en fase 1 can be left in the draw-function in the maintab because that's the same for everyone. But because my fase 2 is something 'personal' for each agent, i'll have to use it in my class (people)?

    I'm just not sure if i put it correctly in there (obviously not because of the error:) ) but could you explain what i'll have to do to put it in there correctly?

    Thanks!

  • edited May 2015

    you understood well

    in the People class:

    boolean FASE2 = false; 
    
  • I'm quite sure it worked, only problem is: when i press 'a' everyone will go towards the door. But after the first one found it and went through it, all the others disappeared... My amountOfPeople is set on 5.

  • when i press 'a' everyone will go towards the door.

    that is good, isn't it?

    after the first one found it and went through it, all the others disappeared...

    that is bad, right?

  • Haha true! Everything goes good for the first one: I start the sketch, 5 persons are wandering through their room. (good!) I press 'a'; when the door is in their view-radius, they'll walk towards it (good!) When the first one goes through the door in the hallway all the others disappear (bad) When he is walking through the hallway he'll stop at the emergencyExit (good!)

  • I guess you got one line setting FASE2 (that is where they flee, right?) to false and instead FASE0 to true

    or set FASE1 to true?

    maybe in

    p.seek(fE1);
    

    ??

    how come, they don't show anymore?

    which var does that??

  • edited May 2015

    Sorry I was eating :). Nope in my People-class this is what i've done for FASE2:

    This is my maintab for FASE2: for (People p: persons) { if (p.FASE2 == true) { p.separation(persons); p.display(); p.bordersHallway(); p.findNearbyExit(); fireHazzard.add(new Fire(new PVector(positionFireX,positionFireY,positionFireZ))); p.fireEscape(); p.update();
    } }

  • edited June 2015

    p

  • sorry about the bad layout, it didn't work like i wanted it to do.

  • how come, they don't show anymore when they reached the door?

    which var does that??

  • That's the problem, i've never face that kind of trouble and i don't think there is a variable responsible for it? It was never an option to disappear. We've got amountOfPeople but that's just a variable with an amount you choose at the start of the sketch. Maybe processing just acts like 'one went through the door, we can go to the next phase, the others don't mather anymore?' I'm just guessing though because i'm not sure...

  • but you wrote that code....

    so what happens when one goes through the door?

  • show class people.

  • edited June 2015

    m

  • edited June 2015

    m

  • is it ok that phases is within the class?

  • edited June 2015

    m

  • do you see that phases in the class is almost the same as what you have in draw()?

    that can not be good

  • also line 199 above: not sure...

    maybe make // before this?

  • You mean for fase0 and 1 i use a setup that's quite similar? It's some code-duplication but i don't think it's a problem for the performance of my program?

    If i put a comment before line 199 they all just 'hang out' at the door, i think because they don't realize they're ready for the next phase.

  • ok, i got 10 more minutes

    post your entire code

  • edited June 2015

    m

  • Do you need the other ones too, i guess not because those work?

  • entire

  • as I said

  • clock is ticking....

  • edited June 2015

    m

  • edited June 2015

    m

  • edited June 2015

    m

  • sorry, I can't run it here....

    sorry....

    all I can say, that it is weired that you have phases inside the class, because you loop over all people there

    and because

     if (start == true) {
          FASE0 = true;
        }
    

    sorry, I have to go...

    ;-)

Sign In or Register to comment.