So I have a situation where I want a hungry actor to pick up food when he’s *not* eating, but not when he’s already eating. From the actor’s perspective, it’s pretty easy in GameSalad. You simply detect the collision from that actor, have an internal boolean variable about whether you’re hungry or not, and take action accordingly. However, what about the food? It can detect that it’s overlapped with an actor, but without using Crazy Global Variables or something, there’s *no* way it can know if that actor is hungry or not. The solution?
Two identical-looking actors. One hungry actor, one non-hungry actor. When the non-hungry actor gets hungry, he spawns a hungry copy of himself and Destroys himself. The same going the other way.
Ok so far as it goes. The food knows whether to disappear or not because it knows it’s collided with either a hungry actor or a non-hungry actor. However, there is *one* tiny problem:
There are other variables that must be passed from the non-hungry actor to the hungry one.
So I *could* use some global variables to pass this info and *hope* that two different actors don’t step on each other. However, that’s messy, and likely to fail spectacularly at some critical time during my Nobel Acceptance Speech, so I wanted to try something else. The solution? Take your medicine!
I have two variables, one for Health, and one for Hunger. Both must be passed to the next incarnation. I had the idea that I could create objects from the Destroying actor that the Spawned actor would detect upon his creation, then set the variable accordingly. Originally I simply had a Health Pill and a Hunger Pill, and I generated the correct number from our noble, dieing actor for the next actor to Collide with. However, GameSalad doesn’t seem to handle multiple simultaneous collisions correctly, so instead of ending up with a health of 4 when I dropped 4 Health Pills, he ended up with a health of 1, but all of the pills still (correctly) destroyed themselves when they detected the collision.
The solution? Pills for each value. So now I have a One Health Pill, a Two Health Pill, etc. And this works! When I put pills of various values for the next actor to pick up, they are correctly detected by the actor, who sets his Health and Hunger accordingly, and the pills destroy themselves upon collision!