Counting spawned actors?
Guardian
Member Posts: 54
I am spawning in 30 actors using a timer that cuts off when the total number of actors is 30 or more.
Each actor has the attribute self.random set to random(0,1).
Then if self.random is equal to 0 I set game.count0 to game.count0+1.
Then if self.random is equal to 1 I set game.count1 to game.count1+1.
So this should give me a count of the number of actors with 0's and the number of actors with 1's.
However, the counts seem to just continually increase.
Any known issues?????
Kind regards,
Guardian
Each actor has the attribute self.random set to random(0,1).
Then if self.random is equal to 0 I set game.count0 to game.count0+1.
Then if self.random is equal to 1 I set game.count1 to game.count1+1.
So this should give me a count of the number of actors with 0's and the number of actors with 1's.
However, the counts seem to just continually increase.
Any known issues?????
Kind regards,
Guardian
Comments
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Here is the project:
***link removed***
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
So still stuck.
Maybe something to do with spawning in actors???
The other way to do it might be to change 'self.random' to another number _after_ the counter has been incremented.
The counter is incremented when a new actor spawns in from breeding.
I initially spawn 30 actors. They only breed when there are less than 30 actors. These actors are eaten by the player (-1 from count). So more actors are created until 30 is reached (+1 to count). That all works!
What doesnt work is actor is each actor is either male or female. I try to count up each sex so that I can balance it. The count does actually remain balanced... but just keeps counting up and up and up.
I would change it to another value but I use that value later to determine if two actors can breed.
My logic is sound and I cant 'see' a mistake...
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
My best guess is that your initial concern about a problem with the random number is in fact the cause. Specifically, I think the random number generation is ... not happening fast enough?
When malecount=femalecount
.....change sex to random(0,1)
Otherwise
I think the random number is getting set when the condition is true BUT the Otherwise section is also running...? I'm a little lost tbh but getting closer.
Another odd thing: if I turn off the random(0,1) behavior and replace it with a Change Attribute self.Sex to 0, it crashed the game. :-O
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
You need a way to only check that condition once and then disable the rule that checks it.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
game.malecount=game.femalecount should only run once per actor as I set self.BugSetUp=true which means the containing rule only ever runs once. So I'm not sure how existing bugs will change their gender. Unless somehow their gender was linked.
I think there is a problem with spawning lots of actors at the same time and using random values. As previously i found the bugs would spawn in the same place with the same attributes, but I got around that one.
I may have to strip things right back to prove this is the case.
Actors are spawned in and counted. Each actor is randomly allocated a 1 or 2. The number of actors with 1 are counted. The number of actors with 2 are counted.
HOWEVER the latter counts go crazy.
https://www.dropbox.com/s/xn41gy8okfhfdyw/test.zip
Looks like a bug to me????
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
The solution is to save a copy of the attributes first. Then check compare the copies. Then change the game.attributes.
Pffff... that was a bad ass problem...