GML Unable To Find My GML Transitions Problem!

BlueBot5000

Member
So as i go about shaun's tutorial here


i finally finish my transition and polish it before the moment of truth...

and my transition did not work pressing "R" did the first transition part but it did NOT de-transition! it's just a blank black screen how can i fix this?

CREATE EVENT
Code:
/// @description Size Some Variables And Mode Setup

w = display_get_gui_width();
h = display_get_gui_height();

h_half = h * 0.5;

enum TRANS_MODE
{
    OFF,
    NEXT,
    GOTO,
    RESTART,
    INTRO

}
mode = TRANS_MODE.INTRO; //0 = Off, 1 = Next, Remember That!
percent = 1;
target = room;
STEP EVENT
Code:
/// @description Progress Our Transition

if (mode != TRANS_MODE.OFF)
{
    if (mode == TRANS_MODE.INTRO)
    {
        percent = max(0,percent - max((percent/10),0.005));
    }
    else
    {
        percent = min(1,percent + max(((1 - percent)/10),0.005));
    }

    if (percent == 1.4) || (percent == 0)
    {
      switch (mode)
      {
        case TRANS_MODE.INTRO:
        {
           mode = TRANS_MODE.OFF;
           break;
        }
        case TRANS_MODE.NEXT:
        {
           mode = TRANS_MODE.INTRO;
           room_goto_next();
           break;
        }
        case TRANS_MODE.GOTO:
        {
           mode = TRANS_MODE.INTRO;
           room_goto(target);
           break;
        }
        case TRANS_MODE.RESTART:
        {
           room_restart();
           break;
        }
      }
   }
}
DRAW GUI
Code:
/// @description Draw Our Fade Effect

if (mode != TRANS_MODE.OFF)
{
    draw_set_color(c_black);
    draw_rectangle(0,0,w,percent*h_half,false);
    draw_rectangle(0,h,w,h-(percent*h_half),false);
}

draw_set_color(c_white);
draw_text(50,50,string(percent));
SCRIPT
Code:
function SlideTranstition()
{
with (objRoomChangingController)
{
   mode = argument[0];
   if (argument_count > 1) target = argument[1];
}
}
 

FrostyCat

Member
percent will never get to 1.4. That is one of two reasons why your condition is not setting off.

Here is the other:
A lot of rookies have this flimsy habit of implementing "crossing-the-line" behaviours as == comparisons. This nonsense needs to stop.

The problem with this == approach is how easy it is to overstep the line and miss it altogether. For example, if the threshold is at 100 and you check for it using ==, starting at 0 and incrementing by 5 works but not starting at 0 and incrementing by 7. The same threshold checked with >= is fine both ways.

This gets even more problematic when the increments contain fractional components. Not only can the aforementioned overstepping still happen, but floating point arithmetic errors are also involved now. Even theoretically certain thresholds can sometimes be missed if you insist on ==.

The next time you need to implement similar patterns, stay away from ==. Use <= or >= and err on the side where the off amounts will likely lie.
 
Top