• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Could someone help me please. I'm having an error, the error started when I moved the code to the script

K

Konlyns

Guest
############################################################################################
ERROR in
action number 1
of Create Event
for object <undefined>:

Variable <unknown_object>.spd(100008, -2147483648) not set before reading it.
at gml_GlobalScript_PlayerStateFree (line 6) - hspd = move * spd;
############################################################################################
gml_GlobalScript_PlayerStateFree (line 6)

var move = key_right - key_left;

hspd = move * spd;

vspd = vspd + grv;
 

Evanski

Raccoon Lord
Forum Staff
Moderator
############################################################################################
ERROR in
action number 1
of Create Event
for object <undefined>:

Variable <unknown_object>.spd(100008, -2147483648) not set before reading it.
at gml_GlobalScript_PlayerStateFree (line 6) - hspd = move * spd;
############################################################################################
gml_GlobalScript_PlayerStateFree (line 6)

var move = key_right - key_left;

hspd = move * spd;

vspd = vspd + grv;
open the script

put all the code inside
GML:
function PlayerStateFree(){


//PUT ALL CODE HERE

}
 
K

Konlyns

Guest
EvanSki
I did what you said but still giving error

############################################################################################
ERROR in
action number 1
of Create Event
for object <undefined>:

Variable <unknown_object>.hspd(100009, -2147483648) not set before reading it.
at gml_GlobalScript_PlayerStateFree (line 11) - if (hspd != 0) image_xscale = sign(hspd);
############################################################################################
gml_GlobalScript_PlayerStateFree (line 11)
 

Evanski

Raccoon Lord
Forum Staff
Moderator
EvanSki
I did what you said but still giving error

############################################################################################
ERROR in
action number 1
of Create Event
for object <undefined>:

Variable <unknown_object>.hspd(100009, -2147483648) not set before reading it.
at gml_GlobalScript_PlayerStateFree (line 11) - if (hspd != 0) image_xscale = sign(hspd);
############################################################################################
gml_GlobalScript_PlayerStateFree (line 11)
Could you show us the full PlayerStateFree script?
 
K

Konlyns

Guest
EvanSki
script_execute(get_input);

#region Movimentação
function PlayerStateFree(){
var move = (key_right - key_left);

hspd = move * spd;

vspd = vspd + grv;

if (hspd != 0) image_xscale = sign(hspd);

//Colisão Horizontal
if place_meeting(x+hspd,y,obj_wall)

while (!place_meeting(x+sign(hspd),y,obj_wall))
{
x = x + sign(hspd);
}
hspd = 0;

x = x + hspd;

//Colisão Vertical
if place_meeting(x,y+vspd,obj_wall)
{
while (! place_meeting(x,y+sign(vspd),obj_wall))
{
y = y + sign(vspd);
}
vspd = 0;
}
y = y + vspd;

//Jump
if place_meeting(x,y+1,obj_wall) and key_jump
{
vspd -=8;
}
#endregion

#region Tiro

var flipped = direction;
var gun_x = (x+4)*(flipped)
var _xx = x + lengthdir_x(15,image_angle)
var y_offset = lengthdir_y(-20,image_angle)
if key_shoot and global.bullets > 0
{
audio_play_sound(Sound1,1,0)
with (instance_create_layer(_xx,y+10,"Shoot",obj_shoot))
{
global.bullets--;
//Velocidade do tiro
speed = 20;
//Direção
direction = -90 + 90 * other.image_xscale;
//Angulo
image_angle = direction;
}
}
#endregion

if global.life < 1 {
game_restart();
}


#region Troca de Sprite

if (hspd != 0) image_xscale = sign(hspd);

if (!place_meeting(x,y+1,obj_wall))
{
sprite_index = spr_player_jumpinicial;
if (sign(vspd) > 0.5) sprite_index = spr_player_jumpfinal; else sprite_index = spr_player_jumpinicial;

}
else
{
if (hspd !=0)
{
sprite_index = spr_player_running;
}
}
if hspd = 0 {
if place_meeting(x,y+1,obj_wall) {
sprite_index = spr_player_idle
}
}

if hspd != 0 {
if place_meeting(x,y+1,obj_wall){
sprite_index = spr_player_running;
}



}
}
#endregion
 

Roldy

Member
EvanSki
script_execute(get_input);

#region Movimentação
function PlayerStateFree(){
var move = (key_right - key_left);

hspd = move * spd;

vspd = vspd + grv;

if (hspd != 0) image_xscale = sign(hspd);

//Colisão Horizontal
if place_meeting(x+hspd,y,obj_wall)

while (!place_meeting(x+sign(hspd),y,obj_wall))
{
x = x + sign(hspd);
}
hspd = 0;

x = x + hspd;

//Colisão Vertical
if place_meeting(x,y+vspd,obj_wall)
{
while (! place_meeting(x,y+sign(vspd),obj_wall))
{
y = y + sign(vspd);
}
vspd = 0;
}
y = y + vspd;

//Jump
if place_meeting(x,y+1,obj_wall) and key_jump
{
vspd -=8;
}
#endregion

#region Tiro

var flipped = direction;
var gun_x = (x+4)*(flipped)
var _xx = x + lengthdir_x(15,image_angle)
var y_offset = lengthdir_y(-20,image_angle)
if key_shoot and global.bullets > 0
{
audio_play_sound(Sound1,1,0)
with (instance_create_layer(_xx,y+10,"Shoot",obj_shoot))
{
global.bullets--;
//Velocidade do tiro
speed = 20;
//Direção
direction = -90 + 90 * other.image_xscale;
//Angulo
image_angle = direction;
}
}
#endregion

if global.life < 1 {
game_restart();
}


#region Troca de Sprite

if (hspd != 0) image_xscale = sign(hspd);

if (!place_meeting(x,y+1,obj_wall))
{
sprite_index = spr_player_jumpinicial;
if (sign(vspd) > 0.5) sprite_index = spr_player_jumpfinal; else sprite_index = spr_player_jumpinicial;

}
else
{
if (hspd !=0)
{
sprite_index = spr_player_running;
}
}
if hspd = 0 {
if place_meeting(x,y+1,obj_wall) {
sprite_index = spr_player_idle
}
}

if hspd != 0 {
if place_meeting(x,y+1,obj_wall){
sprite_index = spr_player_running;
}



}
}
#endregion
First use the code block provided in the forum when posting code. It is on the toolbar and look like </>
1598474300067.png

Second I assume you are going through a Spaulding tutorial or guide. These guides where written before 2.3 and you will either need to modify them to work with 2.3 or find a 2.3 tutorial.

In general with 2.3 you should not be using script_execute (it can still be used and has a place, but not generally). Instead you need to be calling functions that are declared inside scripts. If you have code outside of a function block in a script then you need to be aware of what scope that code will be run in.

Please review the manual for 2.3 by pressing F1 in the GMS2 IDE; read the sections that cover scripts, functions, objects, instances and variable scope. If you are going to be using an outdated tutorial then you will need to know how to revise it to get it to work. Otherwise, revert back to 2.2.5 and continue to follow the tutorial.

For the current problem. How are you calling this script or function, from which instance, and which events.? Show the whole call stack. Most likely PlayerStateFree is being called from another global script.
 
Top