How many people are at the school?
SpaceCap
Member Posts: 1
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
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
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.
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
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
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
If the condition of the rule is to collide then the otherwise will run when they are not colliding.
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.