Legacy GM Help

P

Potato

Guest
I just started using Game Maker Studio,so I went to the learn section to learn how to make a platformer.I copied the code from the Platformer Basics video.But since I just started I have no idea what I'm doing.But after coping
the code (making a&d the way to move) I got this error.

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

Variable obj_player.key_left(100010, -2147483648) not set before reading it.
at gml_Object_obj_player_StepNormalEvent_1 (line 7) - move = key_left + key_right;
############################################################################################

Can someone help me?
 
J

Jordan Robinson

Guest
Get ready to make lots of mistakes! This is how everybody learns :)

The error message you are getting says that there is a problem in your object obj_player, stating that the variable key_left hasn't been assigned a value before you used it. My guess is you skipped a bit of code when you copied it:
Something along the lines of:
Code:
var key_left = -keyboard_check(vk_left);
var key_right = keyboard_check(vk_right);
 
X

Xskode

Guest
okay what you have above is only going to work after setup a value for the variable key_left.
honestly there is a better way of doing the samething- and it is more flexable too.

if all you're trying to do is make player move when pressing the button you can do the following

in Create Event:
Code:
move_spd = 7 (or whatever number you want to put for player's moving speed)
in Step Event:
Code:
if keyboard_check(vk_left)
   {
      x -= move_spd;
   }

if keyboard_check(vk_right)
   {
     x += move_spd;
   }

that will move player when player press left or right key(s)
and you can add more thing if you setup the movement controls like i just showed you.

There are many other ways- but this is the most easiest and still powerful.

was this what you were looking for?
 
P

Potato

Guest
okay what you have above is only going to work after setup a value for the variable key_left.
honestly there is a better way of doing the samething- and it is more flexable too.

if all you're trying to do is make player move when pressing the button you can do the following

in Create Event:
Code:
move_spd = 7 (or whatever number you want to put for player's moving speed)
in Step Event:
Code:
if keyboard_check(vk_left)
   {
      x -= move_spd;
   }

if keyboard_check(vk_right)
   {
     x += move_spd;
   }

that will move player when player press left or right key(s)
and you can add more thing if you setup the movement controls like i just showed you.

There are many other ways- but this is the most easiest and still powerful.

was this what you were looking for?
So where do I insert the Step Event?

Code:
//get the player's input
key_d = keyboard_check(ord("D"));
key_a = -keyboard_check(ord("A"));
key_jump = keyboard_check_pressed(vk_space);

//react to inputs
move = key_left + key_right;
hsp = move * movespeed;
if (vsp < 10) vsp += grav;

if (place_meeting(x,y+1,obj_wall))
{
    vsp = key_jump * -jumpspeed
}

//horizontal collision
if (place_meeting(x+hsp,y,obj_wall))
{
    while(!place_meeting(x+sign(hsp),y,obj_wall))
    {
        x += sign(hsp);
    }
    hsp =0;
}

//vertical collision
if (place_meeting(x,y+hsp,obj_wall))
{
    while(!place_meeting(x,y+sign(vsp),obj_wall))
    {
        y += sign(vsp);
    }
    vsp =0;
}

x += hsp;
y += vsp;
 
X

Xskode

Guest
So where do I insert the Step Event?

Code:
//get the player's input
key_d = keyboard_check(ord("D"));
key_a = -keyboard_check(ord("A"));
key_jump = keyboard_check_pressed(vk_space);

//react to inputs
move = key_left + key_right;
hsp = move * movespeed;
if (vsp < 10) vsp += grav;

if (place_meeting(x,y+1,obj_wall))
{
    vsp = key_jump * -jumpspeed
}

//horizontal collision
if (place_meeting(x+hsp,y,obj_wall))
{
    while(!place_meeting(x+sign(hsp),y,obj_wall))
    {
        x += sign(hsp);
    }
    hsp =0;
}

//vertical collision
if (place_meeting(x,y+hsp,obj_wall))
{
    while(!place_meeting(x,y+sign(vsp),obj_wall))
    {
        y += sign(vsp);
    }
    vsp =0;
}

x += hsp;
y += vsp;



getting player's input is create event

and reaction to input is step event.

Edited :
your code is missing something.

Code:
key_left = -keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
like mentioned above. that should set a value to the two variables you received error from.
and you should place those is the create event as well.

I put your code into a blank project to find out the problem.

first things are
  1. have an object called 'obj_wall'
  2. set value for variable ' -jumpspeed'
  3. set value for variable ' grav '
  4. set value for variable ' movespeed '
after doing that no more errors came up and i could move left to right

you can set the value of those variables in create or in step. your call
 
Last edited:
P

Potato

Guest
ok so I did what you said and I got a other error with movespeed part.

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

Variable obj_player.movespeed(100011, -2147483648) not set before reading it.
at gml_Object_obj_player_StepNormalEvent_1 (line 9) - hsp = move * movespeed = 4;
############################################################################################
 
X

Xskode

Guest
ok so I did what you said and I got a other error with movespeed part.

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

Variable obj_player.movespeed(100011, -2147483648) not set before reading it.
at gml_Object_obj_player_StepNormalEvent_1 (line 9) - hsp = move * movespeed = 4;
############################################################################################
yes, I add the edited version up above.

you need to set a value for the following variables
Code:
grav = 0.5;
movespeed = 3;
jumpspeed = 7;
you can set the value to any number, the numbers i used was just to test things out.

and then after that, you need to create an object and name it
obj_wall

once you do that you should receive any errors.

if you still do, let me know and we'll fix the problem.

UPDATE :
since the code you just show has
obj_player.
make sure the program for moving player is on an object named
obj_player
or else you will receive an error because you would be calling for a variable that was not placed in
the obj_player
 
A

Aura

Guest
You'll always keep getting errors if you don't understand what you are doing IMO. Using such an advanced method with no prior knowlege of GML is a bad idea. Even if you want to make a platformer with this code, you should have asked what it does instead of repeatedly asking how to fix errors that you have no idea about. Otherwise I'd suggest you to use a simpler method until your GML experience increases. And stop copying code. Learn the mechanism and write the code on your own. Best of luck! :)
 
P

Potato

Guest
You'll always keep getting errors if you don't understand what you are doing IMO. Using such an advanced method with no prior knowlege of GML is a bad idea. Even if you want to make a platformer with this code, you should have asked what it does instead of repeatedly asking how to fix errors that you have no idea about. Otherwise I'd suggest you to use a simpler method until your GML experience increases. And stop copying code. Learn the mechanism and write the code on your own. Best of luck! :)
Thanks for the advice,now may this thead sink into page 2.:banana:
*flush*
 
Top