GML cant find way back RTS

Discussion in 'Programming' started by Swegm, Jun 5, 2018.

  1. Swegm

    Swegm Member

    Joined:
    Apr 23, 2017
    Posts:
    106
    Hi!

    I have a problem wich i have solved before but cant remember how i did that.
    Problem is my unit goes gathering resources
    when he will go back to his house delivering the resources
    he just runs around and can't find the way back. (He also seems to double the speed)

    my code looks like this


    var goto_res
    goto_res = instance_nearest(x,y,obj_resource)
    var goto_house
    goto_house = instance_nearest(x,y,obj_house)

    while obj_house goto_tree = true && carry = 0
    {
    mp_potential_step(goto_res.x,goto_res.y,movespeed,true)
    }
    // resource gather
    if place_meeting(x+2,y+2,obj_resource) && carry = 0
    {
    carry = carryMax
    }
    if carry = carryMax
    {

    mp_potential_step(goto_house.x,goto_house.y,movespeed,true)

    }
    if place_meeting(x+2,y+2,obj_house) && carry = carryMax
    {
    carry = 0
    }
     
    Last edited: Jun 5, 2018
  2. Swegm

    Swegm Member

    Joined:
    Apr 23, 2017
    Posts:
    106
    I understand the problem now but can't solve it, please help. it must be my While function that mess it all up :(
     
  3. Jdown79

    Jdown79 Member

    Joined:
    Aug 21, 2016
    Posts:
    69
    AFAIK you're moving twice as fast because your diagonal speed is faster than your horizontal, debug it to confirm


    /// draw event
    var dis = abs(x - xprevious);
    draw_text(view_xview + 20, view_yview + 20, "realSpd: " + string(dis));
     
  4. Swegm

    Swegm Member

    Joined:
    Apr 23, 2017
    Posts:
    106
    yeah maybe thats why. but my problems solved when i delete the code where the WHILE function starts.. i cant understand how to fix this.. cause i need that while

    anyway thanks for the answer
     
  5. Jdown79

    Jdown79 Member

    Joined:
    Aug 21, 2016
    Posts:
    69
    Code:
    while obj_house goto_tree = true
    is this formatted right?

    What are you saying here? while obj_house exists?
    Code:
     
    while(object_exists(obj_house))
    {
    if goto_tree = true && carry = 0
    {
    
    }
    }
    
    I'm no expert but that while statement looks wrong to me, explain what you want that while to do?
     

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