GMS 2 step events are buggy

Discussion in 'Programming' started by DaDonMike, Jul 23, 2018.

  1. DaDonMike

    DaDonMike Member

    Joined:
    Jul 23, 2018
    Posts:
    44
    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.
     
  2. CptChuckles

    CptChuckles Member

    Joined:
    Aug 9, 2016
    Posts:
    80
    I don't know what you mean by this. Post code examples and try to be more descriptive of what you mean.

    Did you know that Step and Draw events are called every frame? Try reading the manual.
     
  3. Dengar

    Dengar Member

    Joined:
    Jun 21, 2016
    Posts:
    285
    show your gms1 code and gms2 code so we can compare
     
  4. DaDonMike

    DaDonMike Member

    Joined:
    Jul 23, 2018
    Posts:
    44
    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
     
  5. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,019
    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.
     
  6. DaDonMike

    DaDonMike Member

    Joined:
    Jul 23, 2018
    Posts:
    44
    ah i do use global. alot how else can i get a variable from one instance to work in another?
     
  7. Kyon

    Kyon Member

    Joined:
    Jun 27, 2016
    Posts:
    469
    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?
     
  8. noobhere

    noobhere Member

    Joined:
    Jul 19, 2018
    Posts:
    26
    I guess something like instance.? instance.x; instance.y; instance.image_index; instance.random_var;....
     
  9. DaDonMike

    DaDonMike Member

    Joined:
    Jul 23, 2018
    Posts:
    44
    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.
     
  10. DaDonMike

    DaDonMike Member

    Joined:
    Jul 23, 2018
    Posts:
    44
    still iv no idea how that will stop it looping from a step or draw event?
     
  11. noobhere

    noobhere Member

    Joined:
    Jul 19, 2018
    Posts:
    26
    @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
    }
     
  12. DaDonMike

    DaDonMike Member

    Joined:
    Jul 23, 2018
    Posts:
    44
    hmm thats an idea, set it back to 0 when its been called, ill try that in the future.
     
  13. DaDonMike

    DaDonMike Member

    Joined:
    Jul 23, 2018
    Posts:
    44
    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?
     
  14. Jdown79

    Jdown79 Member

    Joined:
    Aug 21, 2016
    Posts:
    69
    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?
     
  15. DaDonMike

    DaDonMike Member

    Joined:
    Jul 23, 2018
    Posts:
    44
    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.
     
  16. The-any-Key

    The-any-Key Member

    Joined:
    Feb 2, 2017
    Posts:
    1,521
    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 likes this.
  17. DaDonMike

    DaDonMike Member

    Joined:
    Jul 23, 2018
    Posts:
    44

    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
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice