Question - Code Script causing game freeze.

Discussion in 'GameMaker Studio 2 Community Tech Support' started by p4stoboy, Jan 7, 2019.

  1. p4stoboy

    p4stoboy Member

    Joined:
    Nov 6, 2018
    Posts:
    15
    Hey guys, I've tried running this in debug and the debug console literally populates with nothing, no error is thrown either; I know it is executing this script (breed) because It was throwing errors from within the script before I fixed them and the game started freezing:

    This:
    Code:
        if(place_meeting(x,y,target)){
            mate = target;
            motion_set(0,0);
            with(target){
                mate = other;
            }
            breed(target, id);
        }
    }
    Calls this:

    Code:
    var mother = argument[0];
    var father = argument[1];
    
    var xx = irandom_range(mother.x - 50, mother.x + 50);
    var yy = irandom_range(mother.y + 50, mother.y - 50);
    
    var multi = multiplier();
    
    var child = instance_create_layer(xx, yy, "Instances", o_male);
    with(child){
    hp = ((father.hp + mother.hp) / multi);
    attack = ((father.attack + mother.attack) / multi);
    projSpeed = ((father.projSpeed + mother.projSpeed) / multi);
    moveSpeed = ((father.moveSpeed + mother.moveSpeed) / multi);
    speed = moveSpeed;
    bred = true;
    }
    father.bred = true;
    father.mate = noone;
    father.target = noone;
    mother.mate = noone;
    
    Which freezes the app and causes it to stop responding.

    multiplier() is literally just return irandom_range(1,3);

    I can post the rest of the state machine if need be, there is literally one o_male and one o_female in the room who have very basic behaviours outside of the breed script.
     
    Last edited: Jan 7, 2019
  2. Kyon

    Kyon Member

    Joined:
    Jun 27, 2016
    Posts:
    408
    I believe it is creating a new o_male every step when you collide with 'target'.
    Maybe that's freezing it, maybe its too much. (if your game is 60fps that's 60 instances a second)
     
  3. p4stoboy

    p4stoboy Member

    Joined:
    Nov 6, 2018
    Posts:
    15
    I would agree except that the breed script sets father.bred to true which means it should stop calling the breed script according to its (o_male's) state controller:

    Code:
    /// @description Breed state
    
    if(bred == false){
        if(target == noone && mate == noone){
            target = getTarget();
        }
        if(target != noone && mate == noone){
            move_towards_point(target.x,target.y, speed);
            if(target.mate != noone && target.mate != self){
            target = noone;
            motion_set(0,0);
        }
        }
        if(place_meeting(x,y,target)){
            mate = target;
            motion_set(0,0);
            with(target){
                mate = other;
            }
            breed(target, id);
        }
    }
    else{
        if (counter == 0 || counter mod 120 == 0){
        motion_set(irandom_range(0,359), speed);
        }
        counter++;
    }
     
    Last edited: Jan 7, 2019
  4. p4stoboy

    p4stoboy Member

    Joined:
    Nov 6, 2018
    Posts:
    15
    Fixed, I'm an idiot - there was a typo in multiplier().

    Thanks and sorry.
     

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