Having issues with coding, Please help!

Discussion in 'Programming' started by QuoteTheRobot, Nov 18, 2018.

Tags:
  1. QuoteTheRobot

    QuoteTheRobot Member

    Joined:
    Nov 18, 2018
    Posts:
    10
    Hey! I'm fairly new to the community of GameMaker 2, so I picked up the demo of the software, and dropped by this video () to learn the basics of making games. I've done some coding, (Which I'll show in the image below) but I seem to have run into some.. troubles. There's a bunch of errors, and it's preventing me from starting up the game tester. The errors are as follows:
    Line 21: number of arguments expected 3 got 1
    Line 26: unexpected syntax error
    Line 37: unexpected syntax error
    These are getting pretty annoying, and are preventing me from starting the game, so it would be appreciated if you lent a hand, thanks! -Q.T.R. [​IMG]
     
  2. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,621
    Semicolons have no right to exist at the end of a while loop's head.

    Also check your parentheses () on line 21. Ensure that the amount of opening parentheses equals the amount of closing parentheses.
     
  3. AlexDerFerri

    AlexDerFerri Member

    Joined:
    Aug 24, 2017
    Posts:
    96
    This is the correct code typing:

    Code:
    // Get Player Input
    key_left = keyboard_check(vk_left);
    key_right = keyboard_check(vk_right);
    key_jump = keyboard_check_pressed(vk_space);
    
    // Calculate Movement
    var move = key_right - key_left;
    
    hsp = move * walksp;
    
    vsp = vsp + grav;
    
    if (place_meeting(x, y + 1, oWall)) and (key_jump) {
        vsp = -7;
    }
    
    // Horizontal Collision
    if (place_meeting(x + hsp, y, oWall))
    {
          while (!place_meeting(x + sign(hsp), y, oWall))
          {
                 x = x + sign(hsp);
          }
      
          hsp = 0;
    
    }
    
    x = x + hsp;
    
    
    // Vertical Collision
    if (place_meeting(x, y + vsp, oWall))
    {
          while (!place_meeting(x, y + sign(vsp), oWall))
          {
                 y = y + sign(vsp);
          }
      
          vsp = 0;
    
    }
    
    y = y + vsp;
    Make sure you put the same amount of open/close parenthesis in your code, as TsukaYuriko told you.
    Also, make sure you respect the amount of arguments a specific function requires:


    LINE 21: "x + sign(hsp, y, oWall)" instead of "x + sign(hsp), y, oWall";
    LINE 32: "x, y + sign(vsp)" instead of "x, y + sign(vsp), oWall";
     
    Last edited: Nov 18, 2018
  4. QuoteTheRobot

    QuoteTheRobot Member

    Joined:
    Nov 18, 2018
    Posts:
    10
    Thanks for the help! I've copied down AlexDerFerri's code, but it seems like there's an error. Whenever I hit F5 to boot up the test game, it displays the following:

    ___________________________________________
    ############################################################################################
    FATAL ERROR in
    action number 1
    of Step Event0
    for object oPlayer:

    Variable oPlayer.grav(100009, -2147483648) not set before reading it.
    at gml_Object_oPlayer_Step_0 (line 11) - vsp = vsp + grav;
    ############################################################################################
    --------------------------------------------------------------------------------------------
    stack frame is
    gml_Object_oPlayer_Step_0 (line 11)

    This is pretty odd. Does anyone know how to fix this?
     
  5. QuoteTheRobot

    QuoteTheRobot Member

    Joined:
    Nov 18, 2018
    Posts:
    10
    Never mind. I've done some Debugging, and it seems like I've solved the problem. Thanks for the help, guys! Have a wonderful day!
     
  6. chamaeleon

    chamaeleon Member

    Joined:
    Jun 21, 2016
    Posts:
    975
    Your original code mentioned the use of grv, this code uses grav. Did you update your initial code (that isn't included) that sets the gravity to reflect this?
     
  7. QuoteTheRobot

    QuoteTheRobot Member

    Joined:
    Nov 18, 2018
    Posts:
    10
    Not yet. However, I've done so now, and everything is running smoothly. Thanks for the help, guys.
     
  8. Tony Brice

    Tony Brice Member

    Joined:
    Feb 4, 2017
    Posts:
    67
    Also note the get player input lines at the start of the code. Both the left and right variables you have set to left.
     
  9. backbay

    backbay Member

    Joined:
    Jan 29, 2019
    Posts:
    1

    Hi - I'm an absolute beginner with GM, but it seems to that I've got a similar problem. My error is called

    ___________________________________________
    ############################################################################################
    FATAL ERROR in
    action number 1
    of Create Event
    for object oPlayer:

    Variable oPlayer.move_state(100015, -2147483648) not set before reading it.
    at gml_Object_oPlayer_Create_0 (line 8) - state = move_state;
    ############################################################################################
    --------------------------------------------------------------------------------------------
    stack frame is
    gml_Object_oPlayer_Create_0 (line 8)

    Any idea to get out of this? Many thanks!!
     
  10. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,542
    No, your problem is completely different. The original poster had problems with improper placement of symbols and mistyping an existing variable. Your line suggests neither of these problems.

    State machines are done in several different ways, and you've provided far too little code to tell which one you are using. Here are 4 common methods:
    • If your state is based on numeric values and you intend for move_state to be a mnemonic for a certain value, you should set move_state to that value in an earlier line, OR add it as a macro if you are fine with the name being available project-wide. Choose one, DO NOT do both.
    • If your state is a set sequence of characters, the error means you should surround move_state with double quotes to make it a string. The same should also happen in later code where you check what the current state is.
    • If your state is one of those "script-based" states where it is later run with script_execute(), the error means you have not added the said script. Add that script and name it move_state exactly.
    • If your state is supposed to be in enum form, you need to prepend the name of the enum plus a dot (e.g. player_states.move_state).
    Until you gain the professional judgement to definitively diagnose problems with code, you should NOT bump up old topics with "me too" posts. You saw for yourself how far off the mark you are and how you diluted the reference value of the topic by distracting from it. Make a new topic instead.
     

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