You could then simply call it from each with-loop: / scr_check_outside() if ( y < 0 ) instance_destroy ( )
#Gamemaker studio 2 for loop code
When presented with a snippet of code that is used in multiple places it's a pretty reasonable thing to move it into a script.
It is not ideal and duplicate code means more trouble with editing, but this is most often used. With ( obj_a ) if ( y < 0 ) instance_destroy ( ) with ( obj_b ) if ( y < 0 ) instance_destroy ( ) with ( obj_c ) if ( y < 0 ) instance_destroy ( ) The simplest solution is to include multiple blocks of code (one for each value): So let's consider your options for applying a piece of code to all instances of several types: Sometimes you can cheat by applying the expression to a shared "parent" type of objects, but that is not always the case (and can have side effects if there are more object types meeting the condition). However, initially the same block can not be applied to multiple values, and that's less handy. This can be rather handy under the multiple circumstances. With ( obj_bullet ) instance_destroy ( )
Or an object type (and will apply the expression to each instance of it): Var bullet = instance_create ( x, y, obj_bullet ) with ( bullet ) direction = 180 As you may know, GameMaker Language has a Pascal-like "with" structure:īut it's not exactly like the Pascal version.