• 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 Create event magically running two times

obscene

Member
This is weird...

I have a room with two enemies, which fire lasers (obj_laser_blast). They fire at pretty much the same time. So we have two obj_laser_blasts. This APPEARS to be related to the problem, as baiting only one to fire at me does not cause this problem.

obj_laser_blast creates two instances, light and lensflare. And as soon as obj_laser_blast completes it's work it destroys itself as well as obj_light and obj_lensflare.

So this weird thing keeps happening where extra lights and lensflares get left behind after the laser blast. It's impossible, because in my destroy event I have...

Code:
with lensflare instance_destroy();
with ambientlight instance_destroy();
show_debug_message("obj_laser_blast destroyed with id " +string(id)); // And I know it runs because of this.
So to figure out what's going on I added debug messages when the enemies fire the lasers...

Code:
var laser=instance_create(gunpoint_x,gunpoint_y,obj_laser_blast);
show_debug_message("obj_crawler " +string(id) + " created laser " + string(laser));
 with (laser)
    {
     direction=other.gun_angle;
      friendly=false;
    }
And in my create event I added debug messages to the beginning and end...

Code:
/// Initialize
show_debug_message("obj_laser_blast created with id " +string(id));
fired=false;
friendly=false;
impact=false;
lensflare=noone;
impact_x=0;
impact_y=0;
alarm[0]=2;
lensflare=instance_create(x,y,obj_lensflaregenerate);
lensflare.image_alpha=5;
scr_audio_play_sound_at(snd_laser_blast,1,x,y);
ambientlight=instance_create(x,y,obj_light);
particles=global.particles;

with ambientlight
    {
    image_alpha=1
    }
show_debug_message("obj_laser_blast create event completed with id " +string(id));
So what I discovered is my create event is running two times. Notice the id 116521 appears twice.

upload_2017-4-8_13-5-4.png

And so when the event runs twice, duplicate lights and lensflares are created but the original IDs are overwritten and aren't destroyed in the end.

There is NOTHING in this object that would cause a create event to run twice. Am I correct to assume the only way this would happen is with an event_perform(ev_create,0) call? Because it doesn't exist.

This has driven me absolutely nuts.
 
Last edited:

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
Could you ensure that you did not set "apply to" on the code block in create-event by a chance?
 

obscene

Member
I'm not familiar with that... is it a GM:S 2 thing? (Sorry, forgot to add 1.4 tag til now)

My object...

upload_2017-4-8_13-40-17.png
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
I'm not familiar with that... is it a GM:S 2 thing? (Sorry, forgot to add 1.4 tag til now)

My object...

View attachment 8587
It's right there:
upload_2017-4-8_21-10-38.png
If it's set to "Object:", it'll essentially execute as
Code:
with (obj_laser_blast) {
    // the code inside the code block here
}
So switch that back to "Self" and it should be fine
 

obscene

Member
Wow. I have never seen that before in 3 years of using GM. Must have accidentally changed that. Wow that has driven me nuts.

THANKS.
 
J

jorrit12345

Guest
It's right there:
View attachment 8588
If it's set to "Object:", it'll essentially execute as
Code:
with (obj_laser_blast) {
    // the code inside the code block here
}
So switch that back to "Self" and it should be fine
Thank you so much! I wasted so much time trying to figure out what was going on. Must have accidentally clicked this. This post helped me so much!
 
V

vulhar

Guest
Thanks! I know this is an old thread, but this fixed an issue I was having as well.
 
Top