Access different objects from a loop
Hi everybody,
I'm trying to program 10 different objects which the player can walk around. Basically, as long as the player character's y-coordinate is below that of the object he is drawn in front of it, as soon as it is above that of the object he is drawn behind it.
I set up my 10 objects as active objects. Whenever the player character moves vertically on the screen I want to check whether his y-coordinate relative to each of the 10 objects has changed and then modify his ordering in relation to the affected object.
Here is my problem: Is there a way I can do this with a fastloop? Something like:
1. Start Loop "Walkbehind" "number of obstacle_object" times
2. On Loop "Walkbehind"
if Y("player") < Y("loop_index("walkbehind")")
---> do something to Object("loop_index("walkbehind")")
I don't want to create 10 sets of events, one for checking each object. The problem with fastloops seems to be that I don't know how to access each of the objects y-coordinate seperately and then only modify the players character's order in relation to that one object.
I tried to put the objects into one group of qualifier but that didn't help me because you don't have access to single objects within the qualifier group.
Re: Access different objects from a loop
Give your objects and id by spreading 0 to one of the alterable values at start of level.
On each loop, test if id equals the loopindex, and then perform the action.
But there's an easier way to do what you want. Simply use the layer object's sorting feature and sort by Y decreasing :)
Re: Access different objects from a loop
Thanks for your answer, Popcorn :)
The layer object's sorting feature is exactly what I was looking for.
I also tested the ID spreading method and it works perfectly. Although I don't need it now, it is definitely good to know for the future.
Thank you very much :D
Re: Access different objects from a loop
What I usually do is to put this into the "Joe" object:
Y("Joe") > Y("Ralph")
(under the "Joe" object): Move in front of object "Ralph"
and
Y("Joe") < Y("Ralph")
(under the "Joe" object): Move behind object "Ralph"
It's a bit basic, but it always works nicely... I guess it must go against some common sense in MMF programming, since it looks like the experienced users never use it. I guess I'll find out for myself when things start crashing!
Re: Access different objects from a loop
Well RayMarble, your code is perfectly okay.
The only thing is, if you have more objects than just "Ralph" you would have to create a seperate check for each one of them.
Y("Joe")>Y("Ralph")
Y("Joe")<Y("Ralph")
Y("Joe")>Y("Steve")
Y("Joe")<Y("Steve")
Y("Joe")>Y("Bill")
Y("Joe")<Y("Bill")
...
By using one of the methods which Popcorn suggested you could put all of that in as few as one single event.
Re: Access different objects from a loop
Heh that's true, I have all the characters always following the same path (more or less) and except for overlapping with the player character there aren't that many complicated situations.
Since the layer object has the "sort by Y", I guess I should use it - otherwise I'll end up in trouble if I have more than 5 objects and have to sort them all manually... Although I wanted to use the least possible number of objects for the project it won't do to make things simpler than they should be (as a famous guy said :) Thanks
_O_ (kowtow)