GameMaker step events are buggy

DaDonMike

Member
in gms1 and before you can call a instance from a step event and it only loops it once.

now in gms2 when you draw a instance from a step or draw event it loops and makes loads.

why is this a thing in gms2? its made coding much harder imo.
 
C

CptChuckles

Guest
in gms1 and before you can call a instance from a step event and it only loops it once.
I don't know what you mean by this. Post code examples and try to be more descriptive of what you mean.

now in gms2 when you draw a instance from a step or draw event it loops and makes loads.
Did you know that Step and Draw events are called every frame? Try reading the manual.
 

DaDonMike

Member
i cant use gms1 anymore as its no longer free and the steam one i do have crashes even after a new install.. im now using gms2 mobile.. the best way to put it is this:

object1..
in DRAW event:
if soandso == 1
{
instance_create(x,y,object2)
}

================================

object2..
in CREATE event:
{
ramdom_var += 1
}

so basically the "random_var" will increase FAST in a create event. sorry if its hard to understand its the best way i can explain it to you :)

EDIT: just saw the above post.. yes i do know they are drawn every frame but not in create event if the instance is just sitting in a room after being drawn?

"Try reading the manual" please show me where it is in the manual so i can read it because i clearly missed something here? lol
 

samspade

Member
i cant use gms1 anymore as its no longer free and the steam one i do have crashes even after a new install.. im now using gms2 mobile.. the best way to put it is this:

object1..
in DRAW event:
if soandso == 1
{
instance_create(x,y,object2)
}

================================

object2..
in CREATE event:
{
ramdom_var += 1
}

so basically the "random_var" will increase FAST in a create event. sorry if its hard to understand its the best way i can explain it to you :)

EDIT: just saw the above post.. yes i do know they are drawn every frame but not in create event if the instance is just sitting in a room after being drawn?

"Try reading the manual" please show me where it is in the manual so i can read it because i clearly missed something here? lol
I also am not sure what you mean and the above code looks like a bad idea. It will do the following if soandso == 1 for every view active it will create object2. Object two will then increment its own random_var by 1. It will only do so once. Unless random_var is global in which case that is a bad naming convention.

Further this code would run the exact same way in both GMS and GMS 2.
 

Kyon

Member
What does "soandso" do?
Also you're creating an object in the draw event, don't do that.
Also "instance_create" doesn't work in GMS2 at all right? What is the actual code you have in your game?
 
N

noobhere

Guest
ah i do use global. alot how else can i get a variable from one instance to work in another?
I guess something like instance.? instance.x; instance.y; instance.image_index; instance.random_var;....
 

DaDonMike

Member
sorry not "instance_create" i mean "instance_create_depth" and sometimes i have no choice but to create in a draw event

"soandso" was just a variable i made up for this topic, in this sense if i change it to value of 1 it will call the code i said above.
 
N

noobhere

Guest
@DaDonMike Did you want to create the object2 once? Then change the soandso to any numbers except 1 will stop it. Something like this:
Code:
if soandso == 1
{
 instance_create(x,y,object2)
 soandso = 0 // or any except 1
}
 

DaDonMike

Member
@DaDonMike Did you want to create the object2 once? Then change the soandso to any numbers except 1 will stop it. Something like this:
Code:
if soandso == 1
{
 instance_create(x,y,object2)
 soandso = 0 // or any except 1
}
hmm thats an idea, set it back to 0 when its been called, ill try that in the future.
 

DaDonMike

Member
thinking about it i don't think that will work as it will draw once the whole game or if i set it back to 0 from where i called it from it will draw loads again.. i really think they got to remove the useless spamming of instances or put it as a option?
 
J

Jdown79

Guest
this isnt the fault of the engine, more your code. Yes, in the step event that will "spam" an instance for every time soandso == 1. You could stop it spamming through a number of ways, have a timer to change soandso at a reduced rate, or you could count how many object2's are created, and stop them being created if it exceeds the amount you want.
Also why do you have to have this code in draw?
 

DaDonMike

Member
all types of reasons really but some code i do has to be in draw event and other code has to be called after that code.. iv tried "draw end" event witch does the same thing as its still being called from the looping "draw" event.
 

The-any-Key

Member
but some code i do has to be in draw event and other code has to be called after that code
If you need to run specific code in a specific order. You need to do it different in GMS2. The step events will run in an order you can't predict.
Ex: If you have 3 instances and all use the step event. These 3 can run:
instance 1, instance 2, instance 3
next step
instance 3, instance 2, instance 1
next step
instance 2, instance 1, instance 3
...
Even if you have it on different depths or layers or anything. This is how GMS2 do step events. Yes, you could do it different in GMS1.4 in some cases, but not in GMS2. So you need to forget everything you learned in GMS1.4 about step order and the depth variable.
If you need to run specific code before other code run. Use a controller:
Ex:
Code:
// run step code in all obj_prepare_aim
with obj_prepare_aim
{
   new_angle=direction+90;
}
// run code in rifle
with obj_rifle
{
   if obj_prepare_aim.new_angle>180 allow_fire=true
}
// run code in player fire code
with obj_player
{
   if fire_button
   {
      with instance_create_depth(...) direction=obj_prepare_aim.new_angle
   }
}
But in general it's a bad idea to code this way. Best is to code it in a way you don't need to run specific code before other code. Or al least limit it so you only need to do this in some cases.
 

DaDonMike

Member
If you need to run specific code in a specific order. You need to do it different in GMS2. The step events will run in an order you can't predict.
Ex: If you have 3 instances and all use the step event. These 3 can run:
instance 1, instance 2, instance 3
next step
instance 3, instance 2, instance 1
next step
instance 2, instance 1, instance 3
...
Even if you have it on different depths or layers or anything. This is how GMS2 do step events. Yes, you could do it different in GMS1.4 in some cases, but not in GMS2. So you need to forget everything you learned in GMS1.4 about step order and the depth variable.
If you need to run specific code before other code run. Use a controller:
Ex:
Code:
// run step code in all obj_prepare_aim
with obj_prepare_aim
{
   new_angle=direction+90;
}
// run code in rifle
with obj_rifle
{
   if obj_prepare_aim.new_angle>180 allow_fire=true
}
// run code in player fire code
with obj_player
{
   if fire_button
   {
      with instance_create_depth(...) direction=obj_prepare_aim.new_angle
   }
}
But in general it's a bad idea to code this way. Best is to code it in a way you don't need to run specific code before other code. Or al least limit it so you only need to do this in some cases.

Now thats a reply i was looking for! thank you.. i appreciate the comments above but they don't seem to understand what i was saying! you hit the nail on the head.. i though i was going mad with step event at one point haha
 
Top