Game Development Reference
In-Depth Information
Translation Tips
Here are some general observations about the relationship between D&D actions and
comparable GML code. Try and see if you can find specific examples of each of these points in
the Zool code as you continue to explore the zooldrag.gmk example.
Setting the Relative option is generally equivalent to adding or subtracting a value
from the previous value of a variable. So a Set Variable action that sets the Variable x
Relative to the Value -3 is equivalent to x=x-3 .
A great many actions simply set or test variables that are predefined by Game
Maker. Set Lives sets lives , Test Health tests health , Set Speed sets speed , and so
forth (refer back to Chapter 1 for the full list of predefined variables).
Most conditional actions (the ones with hexagonal icons) translate into if
statements. These if statements are followed by brackets containing an expression;
for example, if(a > b) or if( place_meeting(x,y,obj_object) == true ) . If the
expression is true, then the next statement or block of statements is executed;
otherwise, it is not.
Blocks of statements are grouped within curly brackets ( { and } ) and the code within
them is indented to show which statements are part of that block (just like in the
actions list). Note that this doesn't happen automatically in the code editor and you
will need to manually add tabs to achieve the indentation.
Selecting Other for the Applies To option of an action is equivalent to putting the
statement with(other) in front of the code. This makes the following statement or
block of statements act as if it is operating on the other instance in a collision
instead. Likewise, selecting Object obj_dragon for Applies To is equivalent to putting
the statement with(obj_dragon) in front of that code so that it acts upon all instances
of obj_dragon .
It is possible to set the local variables of another instance after creating it! This is
because the GML equivalent of Create Instance instance_create(x,y,obj) returns
the id of the instance that is created. This id can then be used to set its local
variables. In fact, that's just what our GML version of the Create Moving action does
(see point 25 in the previous section). It assigns a temporary local variable (called
instance ) to store the id and then sets instance.speed and instance.direction ,
accordingly. Using the period ( . ) in this way just means that we're referring to the
local speed and direction variables of the instance.
 
Search WWH ::




Custom Search