Counting spawned actors?

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


Comments

  • DeadlySeriousMediaDeadlySeriousMedia ArizonaMember Posts: 838
    edited February 2013
    You need a counter that counts all 30 total actors regardless of their 1 or 0 value, then tell the other two counters to only count if the total is less than 30.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Nope, no known issues. It should work the way you described it. Post a screenshot of your rules or a link to the project file and we'll get it fixed.

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

  • GuardianGuardian Member Posts: 54
    edited February 2013
    ok, the logic is quite complicated as I'm working on quite a complicated idea of natural selection acting as scaling difficulty. So a screenshot wont cut it.

    Here is the project:

    ***link removed***
  • GuardianGuardian Member Posts: 54
    Watched the video thanks, but I'm using the same basic technique (not tags but integers)

    So still stuck. :(
  • GuardianGuardian Member Posts: 54
    edited February 2013
    Its important to note that I have actually used the technique successfully to count the total number of actors. It's just when I count based on the value of the random attribute it seems to go berserk.

    Maybe something to do with spawning in actors???
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Follow @DeadlySeriousMedia's advice. Only increment the counters when total count is less than 30.

    The other way to do it might be to change 'self.random' to another number _after_ the counter has been incremented.
  • GuardianGuardian Member Posts: 54
    edited February 2013
    @RThurman, thanks but its not a long term solution to my problem.

    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...
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    For some reason I can't download your project. If you want to email it to me, I'll send you my address in a PM.

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

  • GuardianGuardian Member Posts: 54
    Thanks! Sending 10MB down the pipes! :D
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    @Guardian -- something like this?
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited February 2013
    Wow, I've spent a lot of time looking at bugs trying to find a bug. :P

    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

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    OH WAIT! I've got it. The when game.malecount=game.femalecount condition is repeatedly true because those counts are constantly changing when new bugs are spawned. So existing bugs keep changing their genders (and adding to the gender count) before they ever change to self.BugSetUp=true.

    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

  • GuardianGuardian Member Posts: 54
    Yeah, as I said its complicated (but pretty streamline) so I'm not surprised it got your noggin thinking.

    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.
  • GuardianGuardian Member Posts: 54
    thanks for your help guys. I'll report back if I find out the problem.
  • GuardianGuardian Member Posts: 54
    ok, I have boiled down the whole thing to the most simple example.

    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????
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited February 2013
    I added three log debugger statements that display the actor's spawn order (e.g. if it was the 4th one to spawn, the log will show '4'). Theoretically, only one should fire for each spawned actor. You'd expect that since you're essentially using an IF...ELSEIF...ELSE statement. But some of the actors have multiple log statements, indicating that they ran more than one condition (e.g. ELSEIF and ELSE).

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

  • GuardianGuardian Member Posts: 54
    Thanks @tatiang, that narrows it down a bit more. I think there is a bug here that maybe to do with random values resetting on spawned actors. Also @tatiang you'll see in my game that when the player eats a bug for a moment before they die they change colour and size. Can I raise this as an bug here? Or do I have to report it?
  • GuardianGuardian Member Posts: 54
    Bug reported to gamesalad
  • GuardianGuardian Member Posts: 54
    Hey guys, I worked out what the problem is with this. Basically the spawned actors appear changing game.attributes in the process, which is contained within a rule that checks the game.attributes. This basically causes it to recheck and again change the game.attributes. This loops. Add loads more actors doing the very same thing and its a recipe for crazy.

    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...
Sign In or Register to comment.