• 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!

Legacy GM Something about the "with" statement that's confusing me

A

AwesomeAlvin

Guest
So, i've been confused about as to why these different sets of code works different than each other.

So to set up the scene, it's a top down shooter using the physics engine, and I'm confused about the shooting mechanics. One of them works, one of them doesn't.

The one that works:
Code:
bullet = instance_create(x, y, obj_pistol_bullet)
with (bullet) {
    bulletDirection = other.direct;
    physics_apply_impulse(x, y, lengthdir_x(projectileSpeed, bulletDirection), lengthdir_y(projectileSpeed, bulletDirection));
}
So the above code is in the gun object which creates the bullet. The bullet has a parent object and in the create event uses event_inherited(); and also has it's own projectileSpeed.
This is what it looks like in the parent object.
Code:
bulletDirection = noone;
projectileSpeed = noone;
Now, this code works perfectly, but when I try to have the bullet control the impulse instead of the gun, it doesn't seem to work.

So the one that doesn't work, is pretty much the impulse code cut and pasted into the parent object.
When I shoot with this one, then the bullets only travel to the left, and not where I'm pointing.

The direct variable is just the direction of the mouse.

So how come the shooting only works properly when the impulse is controlled by the gun?

Any help would be appreciated, thanks!
 

Tthecreator

Your Creator!
remember that noone is actually just a number equal to -4. The object functions like with statements just interpret it as noone.(If I'm not mistaken).
You might want to change your code:
Code:
bulletDirection = 0;
projectileSpeed = 0;
 

sp202

Member
no-one is usually a keyword reserved for when dealing with object/instance ids. It's what certain id-returning functions default to.
 
A

AwesomeAlvin

Guest
Ah I see. I changed it to 0, but that still doesn't solve why the physics_apply_impulse function doesn't work on the parent object, but works on the gun.
 
Top