GML Object is not moving[SOLVED]

Discussion in 'Programming' started by Enreeper, Jun 15, 2019 at 2:55 AM.

Tags:
  1. Enreeper

    Enreeper Member

    Joined:
    Friday
    Posts:
    5
    i have written a code that let you choose how fast it is and in wich direction it goes, but the object wont move.

    here´s my code

    obj_WallMoving

    MiddleMouseRealesed:

    move_direction=get_string("Type in the direction","")
    move_speed=get_string("Type in the speed","")

    Step:

    ///check if level is started
    if global.playmode=1
    {

    if move_direction=("move_left")
    {
    direction=+45
    speed=("move_speed");
    }

    }
     
  2. Jonar

    Jonar Member

    Joined:
    Dec 9, 2018
    Posts:
    20
    Do you mean that you can't type in the speeds or that the object won't move after you type them in?
     
  3. Enreeper

    Enreeper Member

    Joined:
    Friday
    Posts:
    5
    When im in game and click on the object, the strings works fine, but when i set global.playmode to 1 the object wont move
     
  4. BaBiA Game Studio

    BaBiA Game Studio Member

    Joined:
    Jun 20, 2016
    Posts:
    785
    You are trying to set a number variable (speed) to a string "move_speed". You are not reading the variable called move_speed, you are actually trying to convert the text "move_speed" into a number, which will not work (or it will just convert to 0). Try actually setting the speed variable to the variable move_speed. What you currently have is like the "Hello World" bit of this page: http://docs2.yoyogames.com/index.ht..._reference/type_actions/string_to_number.html
    Try just doing the following:
    Code:
    speed=move_speed;
    and see if that accepts what you have entered as a number to start with. If it doesn't accept it then you will have to convert the text you have entered into a number like this:
    Code:
    code =real(move_speed);
    For more info on converting a string to a real look here: http://docs2.yoyogames.com/index.ht...3_scripting/4_gml_reference/strings/real.html
     
    Enreeper likes this.
  5. Enreeper

    Enreeper Member

    Joined:
    Friday
    Posts:
    5

    OMG It work´s !, thx
     

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