Instance create layer issue

R

Riley

Guest
Hello, I'm new to Game Maker and I'm trying to figure out how to create an attack.
I have it set so that when the F key is pressed there is a new instance of the attack object. But when this happens there are two attack objects that are formed. One is in the correct place and goes through the entire animation. The second is only frame 1 of attack object's animation and is lower than the other attack object. The attack object is called oScream. My code is
if(key_attack){

with(instance_create_layer(x,y,"Scream",oScream)
{

}

}
Any help would be amazing
 

toxigames

Member
Are the two instances of oScream created in the same game step? Or in consecutive steps? If it is the latter then check if key_attack is reset to false before the check for key_attack is done again in the next step . Im interested in knowing where/when exactly do you rest key_attack to false?

If both are created in the same game step I would search through all scripts with "oScream" (excluding the quotes) to see if you have accidentally coded it to be created somewhere else.
 
R

Riley

Guest
Thank you so much for the reply!
I checked for other instances of oScream. I don't have any other instances of oScream anywhere else other than once. And I'm sorry I'm not sure I know what consecutive steps mean.
 

toxigames

Member
Thank you so much for the reply!
I checked for other instances of oScream. I don't have any other instances of oScream anywhere else other than once. And I'm sorry I'm not sure I know what consecutive steps mean.
Yw! :) I mean after each other. For example if the first object instance is created in step 1 and the second instance is created in step 2.

You can keep track at what step your game is in by making a step variable in a controller object, then in it's begin event you just do the following:

Code:
//Create event of object oController:
step = 0;

//Step Begin event of object oController. It's important to do this in the BEGIN step event:
step++;
Then in the oScream objects create event you can do this:
Code:
//Create event of object oScream:
show_message("controller_obj.step: " + string(controller_obj.step));
Then everytime when an oScream instance is created a message box will popup telling you what step it was created in. If both instances are created in the same step then there will be two messages in a row with the same step number. If they are not created in the same step then the step values will be different in each message box.


My guess is that key_attack is still set to true in the the next step for some reason, meaning the code will be run again unintentionally without you having pressed F again. But Im just guessing now. If you could check and/or tell me, exactly when, where and how you reset key_attack to false I think that would help too!
 
Last edited:
R

Riley

Guest
Thank you so much for responding again.
Game Maker is saying that it is created in step 17. But when I tried it again it showed a variety of numbers in the tens. I made sure that the step++ was in oControllers begin step.
Hopefully that helps.
Thank you so much again.
 
Top