How many people are at the school?

I have a simulation with sims that walk around and get things depending on their needs. There is a school where they go and they gain education while they are there. I can't seem to find a way to count how many people are currently at the school learning. I need to be able to measure it so i can set a maximum students value and control how many people can learn at once.

The code is a rule within a rule within a rule etc. When all needs are satisfied the sim goes to the school. I tried adding 1 to a game value "Current Students", but i couldn't figure out where i would put the -1 when the student left. There isn't really any indicator or activator for when the actor suddenly has another need (like thirst or food), where i could put a -1 to current students.

Anyone able to follow this train of thought have any ideas? I could post the code but it's quite long.
Cheers,
-SpaceCap

Comments

  • shark1505shark1505 Member Posts: 75
    I would have an actor at the door of the school called entrance.

    When a sim overlaps or collides with the entrance actor, I would change attribute game.CurrentStudents to game.CurrentStudents+1.

    Then create a self boolean attribute for the sims called InSchool so when they overlap or collide with the entrance actor, it changes to true.
    In the sim actor, create a rule that when self.InSchool is true -
    Timer: after X seconds:
    change attribute self.InSchool to false
    change attribute game.Current Students to game.CurrentStudents-1
    (and your code to leave the classroom)

    Now to set a maximum number of students at school.
    In each sim actor, you have an activator for them to go to school. Add also in the activators that game.CurrentStudents < 30 so that there has to be room for the rule to go to school to be activated.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    If you need to count how many instances of a single actor are on a scene, the easiest way is to add this behavior at the top of the actor:

    Change Attribute game.ActorCount (type index) to game.ActorCount+1

    That way each time the actor appears on the screen or is spawned, it will increase the count by one. If you have actors that leave the scene or are destroyed, you can then decrease game.ActorCount by one when that happens.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    The elaborate further on what @tatiang has said If the school is part of a larger scene then you will need to figure out the boundaries of the school. You could do this by placing an actor and set some game attributes off the actors position to indicate the boundaries or you could simply code the value into your behaviors.

    So looking at the attached pic for example. if the building in the bottom right was the school. then you would use the rules.

    If Self.position.X is Greater than 470 and
    if Self.position.X is less than 568 and
    if Self.position.Y is greater than 64 and
    if Self.position.Y is less than 128
    --Change Attribute game.ActorCount (type index) to game.ActorCount+1
    Otherwise
    --Change Attribute game.ActorCount (type index) to game.ActorCount-1

    You want your game attribute to be an index type so it cannot go into negative numbers.

    You could also accomplish a similar action by simply covering the school area in an invisible actor and tell each student actor

    When overlap or collide with SchoolArea
    --Change Attribute game.ActorCount (type index) to game.ActorCount+1
    Otherwise
    --Change Attribute game.ActorCount (type index) to game.ActorCount-1
  • SpaceCapSpaceCap Member Posts: 1
    Tenrdrmer - Since there is no way i can find to say "When actor uncollides with school actor, change game.ActorCount to game.ActorCount -1" that last bit you said i have tried, and it doesn't seem to work.

    Shark1505 - I think you might have nialed it! Maybe having an entrance door and an exit door, each actor activators which will add and subtract from the current students.

    The only problem i face now is that when a player heads for the school, they go straight for the center of it from wherever they are standing. Ill have to make it so they go in the right door. Also an indicator on the sim that says if they are trying to go to school and not just bumping into the building........

    ack more coding to do..

    Thanks Everyone.
    -SpaceCap
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    @spacecap. Thats What the "otherwise" is for. Everything in there fires when the rule conditions are no longer meet. ie…

    If the condition of the rule is to collide then the otherwise will run when they are not colliding.
  • OniCraftOniCraft Member, BASIC Posts: 43
    Do you already have some sort of path finding method to get the npcs to walk around?
    I'm not good at math, so I just use invisible actors to guide the npcs. I place these guides like checkpoints so that when a npc collides into one, it will know which direction to go to next.
Sign In or Register to comment.