GMS 2 Possible bug? Rate-capping + passing argument = disagreement

Discussion in 'Programming' started by Solitary Confinement, Sep 12, 2019.

  1. Solitary Confinement

    Solitary Confinement Member

    Joined:
    May 20, 2017
    Posts:
    25
    Heya,

    I've tried troubleshooting this quite a bit and was hoping some light could be shed on the issue. I'm attempting to rate-cap without using alarms and followed @FrostyCat 's guide here: https://forum.yoyogames.com/index.php?threads/restricting-unwanted-repetition-with-flags.34455/

    A strange issue I've run into is that I am not able to use a sprite variable as a condition in a script specifically for rate-capping. My setup is as follows:

    Create:
    Code:
    cross_rt=5;
    flag = cross_rt;
    Script that uses the rate-cap:
    Code:
    if myid.char.sprite_index==argument[3]{   
      if (flag <= 0) {
        show_debug_message(random(300))
        flag += cross_rt;
      } else {
        flag -= 1;
      }
    } else {
      flag = cross_rt;
    }
    When I run this, nothing is printed. But, if I replace argument[3] with the actual sprite or even a variable that holds the sprite, it prints fine. Like so:

    Code:
    if myid.char.sprite_index==spr_char_stuff //(or even sp_var_stuff){
      if (flag <= 0) {
        show_debug_message(random(300))
        flag += cross_rt;
      } else {
        flag -= 1;
      }
    } else {
      flag = cross_rt;
    }
    Now, if I have simply the following:

    Code:
    if myid.char.sprite_index==argument[3]
      {show_debug_message(random(300))}
    It prints the numbers.

    So whats going on here? Is this a bug in GMS or am I missing something?

    Thanks for any input.
     
  2. Relic

    Relic Member

    Joined:
    Jun 27, 2017
    Posts:
    689
    Show the whole script please and an example of how you call it.
     
  3. Solitary Confinement

    Solitary Confinement Member

    Joined:
    May 20, 2017
    Posts:
    25
    Thanks for the reply.

    The script is called "scr_addon_brth". The section in question is with the commented header "Cross-hair". Full script code is as follows:

    Code:
    var argument_arr = array_create(argument_count);
    for (var i = 0; i < argument_count; i++) {
        argument_arr[i] = argument[i];
    }
    if (live_call_ext(argument_arr)) return live_result;
    
    //Spc Triggers and System
    /*
    scr_addon_brth(
    "df_lt",    //0
    global.k_lt,    //1
    global.mg_en_flm_req,    //2
    spr_g60_spc_brth_ini, //3
    0.3, //image_speed(ini) //4
    global.snd_shn_brth_ini, //arg5
    
    global.snd_shn_lsr_loop, //6
    spr_g60_spc_brth_aim, //7
    global.mg_en_flm_use,    //arg8
    
    spr_g60_spc_brth_end, //9
    0.02, //image_speed(end) //10
    23, //tic countdown for sound reset (about this much bench'ed to shn's brth sound) //arg11
    "use_en", //use type //12
    0, //can_shoot rate //13
    10, //cancel_allow //14 (def=10, fr=-1)
    -1, //brth duration //15 (def=-1, fr=30)
    )
    
    
    */
    
            
    
    
    //Trigger
    with(myid.char)
    {
    if active==1
    {
        
    if (spc_start_chk)
    {
    if pos=="stand" or pos=="duck"
        {
        if sprite_index==spr_walk
        or sprite_index==spr_stand
        or sprite_index==spr_land
        or sprite_index==spr_duck
            {                           
            if spc_type==argument[0]// and myid.en_curr>=argument[2)       
                {               
                myid.addon.use_type=argument[12]
                
                if (myid.addon.use_type=="use_en" and myid.en_curr>=argument[2])
                or (myid.addon.use_type=="use_am" and myid.ammo_curr>=argument[2])
                or (myid.addon.use_type=="use_am_a" and myid.ammo_a_curr>=argument[2])
                or (myid.addon.use_type=="use_am_b" and myid.ammo_b_curr>=argument[2])
                or (myid.addon.use_type=="use_am_c" and myid.ammo_c_curr>=argument[2])
                or (myid.addon.use_type=="use_am_fr" and myid.ammo_fr_curr>=1
                   and fr_mode==2 and can_fr==1)             
                    {   
                    if myid.addon.use_type=="use_am_fr"
                        {
                        myid.addon_share_alarm.alarm[10]=argument[14];
                        scr_addon_fury_usage(myid.addon.ammo_fr_rld);
                        }
                    else
                        {myid.addon_share_alarm.alarm[10]=argument[14];}
                    can_atk_stand=0
                    can_jump=0
                    can_duck=0
                    atk_state="atk"                       
                    myid.addon.brth_spr=argument[7] //Set the "breath sprite state" to the aim sprite
                    myid.addon_share_alarm.alarm[11]=999//argument[15] //set to proper value in ini to aim transition
                    sprite_index=argument[3]
                    image_speed=argument[4]
                    image_index=0
                    wspeed=0
                    move_prev=1           
                
                    oop=instance_create(x,y,osnd_char_hit);
                    oop.myid=myid;
                    oop.t="c";
                    oop.snd = FMODSoundPlay(argument[5],0);                                 
                    
                    }
            else if (myid.addon.use_type=="use_en" and myid.en_curr<argument[2])
                    or (myid.addon.use_type=="use_am" and myid.ammo_curr<argument[2])
                    or (myid.addon.use_type=="use_am_a" and myid.ammo_a_curr<argument[2])
                    or (myid.addon.use_type=="use_am_b" and myid.ammo_b_curr<argument[2])
                    or (myid.addon.use_type=="use_am_c" and myid.ammo_c_curr<argument[2])
                    or (myid.addon.use_type=="use_am_fr" and myid.ammo_fr_curr<1 and fr_mode!=2 and can_fr!=1)   
                    {
                    if (myid.addon.use_type=="use_en")
                        {scr_ingame_en_lack();}
                    else if ( (myid.addon.use_type=="use_am") or (myid.addon.use_type=="use_am_a") or
                              (myid.addon.use_type=="use_am_b") or (myid.addon.use_type=="use_am_c") or
                              (myid.addon.use_type=="use_am_fr")
                            )
                        {scr_ingame_ammo_lack();}                                               
                    }
                
                }
            }
        }
    
    }
    
    }//active
    
    //Streaming   
    myid.addon.alarm_snd_max=argument[11];
    
    if sprite_index==argument[7]
        {//spr
        //myid.en_curr-=argument[8]
        scr_addon_usage(argument[8])
        image_index=myid.addon.index_pos
        wspeed=0     
        
        //Sound loop system
        with(myid.addon)
            {
            if addon_snd_sys=="alarm"
                {
                if can_snd==1
                    {
                    alarm_snd=myid.addon.alarm_snd_max
                    can_snd=0           
                    oop=instance_create(x,y,osnd_obj)
                    oop.myid=myid;
                    oop.snd = FMODSoundPlay(argument[6],0)               
                    }
                }
                
            else if addon_snd_sys=="loop"
                {
                if can_snd_loop==1
                    {
                    can_snd_loop=0                           
                    oop=instance_create(x,y,osnd_char_loop)
                    oop.myid=myid;
                    oop.snd = FMODSoundLoop(argument[6],0)
                    oop.spr_condit=argument[7]
                    }
                }
                
            }
        
    //Can_shoot rate
    myid.addon.alarm_can_shoot_curr-=1
    
    if myid.addon.alarm_can_shoot_curr<0
        {
        myid.addon.alarm_can_shoot_curr=argument[13]
        myid.addon.can_shoot=1   
        }
            
        }//spr
        
    //Sound rate
    myid.addon.alarm_snd-=1
    
    if myid.addon.alarm_snd<0
        {
        myid.addon.alarm_snd=myid.addon.alarm_snd_max
        myid.addon.can_snd=1   
        }   
    
    }
    
    //Cross-hair
    if myid.control=="player"
    {
    if myid.char.sprite_index==argument[3]{   
      if (flag <= 0) {
        show_debug_message(random(300))
        flag += cross_rt;
      } else {
        flag -= 1;
      }
    } else {
      flag = cross_rt;
    }   
        
    }
    
    //Cancel  (releasing (ini and aim/energy gone/hit)
    with(myid.char)
    {
    if sprite_index==argument[3]
    or sprite_index==argument[7]
        {
        if (myid.addon.use_type=="use_en" and
                (
                    myid.addon.cancel_allow==1 and
                    (
                        myid.en_curr<=argument[8] or
                        (   (myid.control=="player" and spc_type==argument[0] and  !(keyboard_check(argument[1])) ) or
                            (myid.control=="ai" and spc_type=="n")
                        )
                    )
                )
            )
        or (myid.addon.use_type=="use_am_fr" and myid.addon_share_alarm.alarm[11]<0)         
        or active==0
        or hit_state==1
        or pos=="ko"           
            {           
            myid.addon.fire=0
            //spc_type="n"
            //atk_state="n"
            atk_prevs="atk"
            myid.sub_key.key_lock=0           
            can_shoot=1           
                                    
            sprite_index=argument[9]//spr_g90_spc_brth_end
            image_speed=argument[10]
            image_index=0   
            //with(myid.ai)
            //    {scr_ctl_reset();}
            }       
        }
    }
    
    //Firing !*note: firing must ALWAYS go BELOW cancel part in these scripts, otherwise you'll get stray shots since one final projectile instances is created
                //with a different dir just before breath is cancelled, and where the alarm is super low, or even -1.
    if myid.char.sprite_index==argument[7]//"Aim" sprite index is assumed here
    {
    fire=1
    if fire==1 and can_shoot=1
                {//
                can_shoot=0
                scr_proj_brth_cre_inst(brth_proj,brth_amt,brth_spr,dir)           
                alarm_can_shoot_curr=argument[13]     //
                }//   
    }
            
    //anima
    with(myid.char)
    {
    //Initial phase to aim   
    if spc_type==argument[0]
    {
    if sprite_index==argument[3] //the brth ini anima
        {
        if (image_index>=image_number-image_speed) //the final image index before ini animation ends
            {
            myid.addon.can_aim=1           
            myid.addon.fire=1       
            //if facer==1
            //    {myid.addon.dir=argument[12];} //starting direction. Right facing
            //else if facer==-1
            //    {myid.addon.dir=180-(argument[12]);} //starting direction. Left facing   
            image_speed=0;
            //image_index=argument[13];
            image_index=myid.addon.index_pos       
            sprite_index=argument[7]; //the sprite_index of the aim part of brth animation, e.g. spr_shn_spc_brth_mid             
            myid.addon_share_alarm.alarm[11]=argument[15]
            //show_message("hyy2")
            }
        }
    }
    
    
    //End phase to stand/neutral
    if sprite_index==argument[9] //the brth end anima
        {
        if (image_index>=image_number-image_speed)
                        //Recovery determined by IMAGE_SPEED
                        //in scr_addon_brth > argument[ 9
            {
            scr_addon_reset_full();
            #region original reset vars
                
            /*
            myid.addon.can_shoot=1   
            sprite_index=spr_stand
            image_index=0
            image_speed=img_speed
            can_atk_stand=1
            atk_state="n"
            atk_nomov=0
            move_prev=0
            can_jump=1
            can_duck=1   
            */
            #endregion
            }
        }
    }
        
        
    
    
    
    
    The script is called in the step event of a player object as follows. The argument with //3 is the required argument:

    Code:
    scr_addon_brth(
    "df_lt",    //0
    global.k_lt,    //1
    global.mg_en_flm_req,    //2
    sp_brth_ini,//spr_g90_spc_brth_ini, //3
    0.25, //image_speed(ini) //4
    g90_vo_proj_var,    //5 
    global.snd_g90_brth_loop, //6
    
    sp_brth_aim,//spr_g90_spc_brth_aim, //7
    global.mg_en_flm_use, //8
    sp_brth_end,//spr_g90_spc_brth_end, //9
    0.02, //image_speed(end) //10
    500,//sound rate/dummy //11
    "use_en", //12
    -1, //can_shoot rate //13
    cancel_allow_dur_def, //cancel_allow //16 (def=10, fr=-1) //14
    -1, //brth duration //15 (def=-1, fr=30)
    )
    Again posting the create event of the player object (contains several other irrelevant variables, so I've only included the relevant ones):

    Code:
    cross_rt=5;
    flag = cross_rt;
     
  4. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,451
    Did you try printing out sprite_get_name(argument[3]) to see what's ending up in it?
     
  5. Solitary Confinement

    Solitary Confinement Member

    Joined:
    May 20, 2017
    Posts:
    25
    ^ Thank you for the reply.

    I've tried it now and I can see the sprite name appear. However, I had to do this before "flag<=0" check. This is what I have:


    Code:
    if myid.char.sprite_index==argument[3]{  
     show_debug_message(sprite_get_name(argument[3]))
      if (flag <= 0) {
        show_debug_message(random(300))
        flag += cross_rt;
      } else {
        flag -= 1;
      }
    } else {
      flag = cross_rt;
    }
    Also, when using sprite_index==argument[3], if I comment out the "flag = cross_rt" part of the code below the second "else", it prints the numbers fine, but then won't reset flag automatically. This again is strange because if I use the sprite resource name or a variable instead of argument[3], that part doesn't interfere with the code's running.
     

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