Game Development Reference
In-Depth Information
The change_lift_instances Script
1: {
2: var from_obj, into_obj, dx, returned, xpos;
3:
4: from_obj = argument0;
5: into_obj = argument1;
6: dx = argument2;
7:
8: xpos = x + dx;
9:
10: do
11: {
12: returned = instance_place( xpos, y, from_obj );
13:
14: with( returned )
15: instance_change( into_obj, true );
16:
17: xpos = xpos + dx;
18:
19: } until ( returned == noone )
20: }
You should be starting to recognize the structure by now, starting with assigning local
variables to the argument values to make them more readable. There are only three arguments:
a type of object to change from ( from_obj ), a type of object to change into ( into_obj ), and a
horizontal spacing to look for the next lift instance ( dx ). The script also uses the temporary
variables xpos to keep track of the position currently being checked for lifts, and returned to
store the id of any object found.
The script is based around a loop of lines 10-19 until no more objects of the indicated type
are found. However, this is a do , until loop, which works the other way around than a while loop.
There's not much difference, but instead of evaluating the condition in brackets at the start of
the loop, it does it at the end instead (on line 19).
Line 12 does the equivalent of our old check_object_returned script and lines 14 and 15 the
change_instance_for script. Line 17 then advances the position to check for lifts, and line 19
continues the loop unless no object was actually found. In this way, all the adjacent lift
instances of the same type are changed at the same time.
Delayed Lift
One last improvement we'll make to the GML-enhanced version is to fix the small delayed
reaction in Zool's movement when he is standing on lifts. This happens because we update
Zool's movement with respect to lifts in the Begin Step event, but the lifts themselves don't start
or stop moving until the Collision events. We did talk about moving Zool's lift update to after the
Collision events in the End Step event in order to fix this, but that could result in Zool being
pushed through the landscape in certain situations. So to make this work, we need to make some
additional checks to make sure that the lift isn't pushing Zool into the landscape. These checks
hav e n ow be e n adde d to the n e w End Step event of obj_zool_land :
 
Search WWH ::




Custom Search