• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED How to change target of a code

Hey there comrades. It's me, Santa Claus.
I got into the GML undertanding thing and I have to admit: it ain't that different from DnD, eh.
I mean, it's abit harder to keep track of some things (because some actions are not called the same way in DnD) but manageable.
Can't wait to understand it even more and pull out my tech demo.

Anyway, gibberish apart, I've got one problem:
How do I change the target of a code?

I mean, in DnD you can change the target of a block by picking: Self, All, Others, Object (if I'm not wrong).
But on GML I can't find a proper way to do it.
I've searched in the manual of GML if there's something, but it seems I lack the correct keywords to find
what I'm looking for.

H4LP? Thanke.
 

TailBit

Member
GML:
hp=10;

with(object/instance){
    // do stuff in their scope
    other.hp-=1;
}
You can use other in with to get variables from the one initiating with (in collission events, other is the other instance in the collission)

You can also create a instance and remember it
GML:
shield = instance_create_ ...;
rotate = 0

//Then you can do this in step event

rotate += 10
shield.x = x + lengthdir_x(20, rotate);
shield.y = y + lengthdir_y(20, rotate);

// or

rotate += 10
with(shield){
    x = other.x + lengthdir_x(20, other.rotate);
    y = other.y + lengthdir_y(20, other.rotate);
}
Edit: fixed the lengthdir_y that was _x
 
Last edited:
GML:
hp=10;

with(object/instance){
    // do stuff in their scope
    other.hp-=1;
}
You can use other in with to get variables from the one initiating with (in collission events, other is the other instance in the collission)

You can also create a instance and remember it
GML:
shield = instance_create_ ...;
rotate = 0

//Then you can do this in step event

rotate += 10
shield.x = x + lengthdir_x(20, rotate);
shield.y = y + lengthdir_y(20, rotate);

// or

rotate += 10
with(shield){
    x = other.x + lengthdir_x(20, other.rotate);
    y = other.y + lengthdir_y(20, other.rotate);
}
Edit: fixed the lengthdir_y that was _x
Mmmmh I don't think I got it comrade.

I mean, imagine that i have object1 and object2.
Inside the step event of object1 I want to move object2. That's it.

Moving object1 would be something like

x = x + 10

What do I have to write to make this very action appening NOT to object1 but to object2?
 
Top