Greetings all. I know I must be getting old when I can't remember old when I can't do something basic as this. So here goes; I'm making an a run 'n gun action platform. I want to be able to spam cloned enemies and have them do different actions. That isn't hard at all. It's just that they are all doing the same action at the same time. >_<
Also, I want to shoot a bullet and have it take damage off, without it effecting all the clones. Easy stuff I know, but for the life of me, I can't remember how to do it. Thanks in advance for any help.
In MMF coding, theres two parts; the "actions" and "events, like if you had a line saying;
"When space bar is pressed, end the game"
the "When space bar is pressed" would be the action, and the "end the game" would be the event.
Now how MMF works with multiple copies of the same object type, is that when it reads through an action, it starts off with every single copy of that object being in a list, with the topmost object being the newest one. So say you have 5 active objects of the same type, it would be:
object5
object4
object3
object2
object1
If you were to place an event in this line under the object's tab, such as "Destroy object" or "Sub 1 from Value A", it would read this list and apply this action to EVERY object. Hence it would destroy all 5 objects, or sub 1 from all 5 objects value A.
However, when using the events on the left side, you can narrow down which objects are selected. Since it starts with ALL objects by default, having a condition on your event can pick a specific object. So if we insert the line into our event:
"When 'Bullet' collides with 'object'"
then when the event executes, it will take that list of 5 objects, and choose ONLY the single object that the bullet collided with. So the list becomes
object1
or whatever one got struck. Then when it goes to apply the action, it will only reference this single object and only reduce that one's value A by 1.
Where it gets tricky, is that some actions and some events can only refer to a SINGLE instance of this object. So if we had this event:
"Upon pressing space bar, set global value 1 to alterable value A("object")"
then it would take that list, of object1,2,3,4,5, and since it can only set the global value to a single value, it would set it to the TOPMOST object on the list, object5. So despite there being 5 objects, only a single one would be represented.
Hence, if you want, you can simple code it like this:
"When 'Bullet' collides with 'Object', sub 1 from A("object")"
&
"When A("object") < 0, destroy object".
Since each of these reference the single object, only a single one will be hit, instead of all of them, at a time. It runs into a problem if two objects are struck by bullet simultaneously, which you can rectify as:
"When 'Bullet' is overlapping 'Object' && Pick an object at random, sub 1 from A("object")"
"When A("object") < 0 && Pick an object at random, destroy object"
The "Pick an object at random" command will take a single item randomly, but only from the remaining list, NOT every object on the field. So since the first action, the "A < 0" narrowed it down to only the 1-2 objects whos value is less then 0, it will pick only one of those two and kill it.
Yes, sir. I'm in the navy, stationed in Yokosuka Japan. I've been here about a year and a half now.
I can't stand being in the navy, but the way I saw it, it was the only way for a guy like me to have a steady job while living in Japan. (Although I'm gone 7 months out of a year out at sea.) Japan is a great place, expensive, but great.
Edit: Okay, I have a new problem. I have code that has an emeny walk after the hero. The direction is based on the hero's x value. If the enemy's value is less then the heros, the enemy will walk to the left. If it's more, then it will will walk to right. That works perfect. The problem is when the x value = the hero's x value. The enemy will just get stuck quickly shifting walking anim directions from left to right. I tried to make code if the x = the x, but it doesn't always work. any ideas? I want to make the enemy stop and change anim if it equals the hero's x.
yea ... change the if x is less than hero x ... to ... If x is less than or equal to hero x.
or you could change the greater than side .. but decide which side you want and it'll just move slightly more on one side, no big thing, probably won't even be noticeable. And it solves the problem
Or you could just add an extra line of code to tell the enemy what to do when its x = the x of the hero.
Edited by the Author.
LoL ... I misunderstood somehow (not hard cause I'm usually half asleep when online) ... anyways .. the REAL SOLUTION for your "new" problem would be to consider the positions of the edges of the object, and keep the hotspot in mind because that will affect things.
Then what you'll need to do is if x is less than the value of the left edge of the main object OR greater than the value of the right edge of the main object, move the enemy object towards main objects center position. And if x is greater than the value of the left edge and less than the right edge value, then stop the movement of the enemy object.
That will definitely solve it .... sorry about the confusion. ... kinda funny how I mixed it up all backwards like .. I guess I was thinking dyslexicly or something.
Blood of the Ancient One, Seen only as Shadow, Faster than Lightning, Fierce as the Greatest Dragon, Nearly Invisible, Floating in a Dream, Entered through the Demon Door, Destroyer of Evil in a Realm with a Red Sky Scarred, Who could I be ?