1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

Windows Moving Platform Error when Updated to GM Studio 2

Discussion in 'Programming' started by bshadow8, Dec 4, 2019.

  1. bshadow8

    bshadow8 Member

    Joined:
    Jun 29, 2016
    Posts:
    36
    Hello I'm a fairly novice coder, and so I am currently using an old platform game code to ride horizontal moving platforms, I use this code in my players STEP event....
    >>>
    //The code is used to be sure that gravity is used only when you jump on
    //the moving platform and not when you jump through it to be sure that
    //you get the same jumping height
    if place_free(x,y+1) and not position_meeting(x-sprite_xoffset+sprite_width/2,y-sprite_yoffset+sprite_height,TURTLEGOD)
    gravity=.9
    else if position_meeting(x-sprite_xoffset+sprite_width/2,y-sprite_yoffset+sprite_height,TURTLEGOD)
    if vspeed<0 gravity=.9
    else gravity=0
    else gravity=0

    //First this code is just used in precaution that the character
    //doesn't go directly through the platform
    if place_meeting(x,y+vspeed,TURTLEGOD) and vspeed>6 vspeed/=2
    //And this code assing the moving platform that the character is on and
    //then apply its speed to the character itself while keeping him in the air
    platform=instance_position(x-sprite_xoffset+sprite_width/2,y-sprite_yoffset+sprite_height,TURTLEGOD)
    if position_meeting(x-sprite_xoffset+sprite_width/2,y-sprite_yoffset+sprite_height,TURTLEGOD)
    {
    if vspeed>=0
    {
    vspeed=0
    gravity=0
    y=platform.y+sprite_yoffset-sprite_height+platform.vspeed+2
    x+=platform.hspeed
    }
    }
    <<<

    But as I step on one of those moving platforms "TURTLEGOD" after a quick moment I get this error...
    >>>
    ___________________________________________
    ############################################################################################
    FATAL ERROR in
    action number 1
    of Step Event0
    for object MEGALUSALT:

    Variable <unknown_object>.y(1, -2147483648) not set before reading it.
    at gml_Object_MEGALUSALT_Step_0 (line 23) - y=platform.y+sprite_yoffset-sprite_height+platform.vspeed+2
    ############################################################################################
    --------------------------------------------------------------------------------------------
    stack frame is
    gml_Object_MEGALUSALT_Step_0 (line 23)
    <<<

    I also declared variable platform = 0 in the CREATE EVENT

    This error did not pop up on GM Studio 1 so I am betting there's a quick fix can anyone help this lame coder?
     
  2. obscene

    obscene Member

    Joined:
    Jun 21, 2016
    Posts:
    2,469
    That first block of code you posted isn't even possible. Brackets are missing and the formatting is lost. The forum has probably scrambled it. Wrap your code in [ code ] [ /code ] tags and let's try again.

    The error is generally telling you that there isn't an instance of platform.
     
  3. bshadow8

    bshadow8 Member

    Joined:
    Jun 29, 2016
    Posts:
    36
    Great I'll try...
     
  4. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,133
    Your problem is all you are doing is checking if there is a platform colliding with the player, but you set the value of platform to whatever platform is at a particular point on the player. just because there is a collision with a platform doesn't mean at that particular point there is a platform. So platform is getting set to noone and thus you're getting an unknown object error.

    So either use instance_place or rethink your code.
     
  5. bshadow8

    bshadow8 Member

    Joined:
    Jun 29, 2016
    Posts:
    36
    Let me try instance_place...
     
  6. bshadow8

    bshadow8 Member

    Joined:
    Jun 29, 2016
    Posts:
    36
    Yup instance_place did the trick...I'll be looking up the exact difference on these two, and why it counts...thanks a lot, TheouAegis! You're the best.
     
  7. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,133
    Just make sure the player can't collide with 2 moving platforms at the same time and you won't have any issues with instance_place().

    You could still use instance_position(), but you'll need to check at (bbox_left,bbox_bottom+vspd) and (bbox_right, bbox_bottom+vspd), then if one of them returns an actual id, save that to platform. The point is you need to check a minimum of two points with instance_position in this situation.
     

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