Having issues with coding, Please help!

Q

QuoteTheRobot

Guest
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.
 

TsukaYuriko

☄️
Forum Staff
Moderator
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.
 
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:
Q

QuoteTheRobot

Guest
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?
 
Q

QuoteTheRobot

Guest
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!
 

chamaeleon

Member
Variable oPlayer.grav(100009, -2147483648) not set before reading it.
This is pretty odd. Does anyone know how to fix this?
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?
 
Q

QuoteTheRobot

Guest
Not yet. However, I've done so now, and everything is running smoothly. Thanks for the help, guys.
 

Tony Brice

Member
Also note the get player input lines at the start of the code. Both the left and right variables you have set to left.
 
B

backbay

Guest
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?

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!!
 

FrostyCat

Redemption Seeker
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!!
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.
 
Top