xNYARLx
Member
Hello. I make for my child cute frogs who follow them but sometimes i have this error:
ERROR in
action number 1
of Other Event: Animation End
for object obj_env_frog_walk_to_player:
Variable obj_env_frog_walk_to_player.xspeed(100005, -2147483648) not set before reading it.
at gml_Script_move (line 7) - if (place_meeting(x + xspeed, y, collision_object)) {
############################################################################################
gml_Script_move (line 7)
gml_Object_obj_env_frog_walk_to_player_Other_7 (line 8) - move(obj_solid);
There Code, you can use it when u want to your game its no problem:
FROG CODE
ERROR in
action number 1
of Other Event: Animation End
for object obj_env_frog_walk_to_player:
Variable obj_env_frog_walk_to_player.xspeed(100005, -2147483648) not set before reading it.
at gml_Script_move (line 7) - if (place_meeting(x + xspeed, y, collision_object)) {
############################################################################################
gml_Script_move (line 7)
gml_Object_obj_env_frog_walk_to_player_Other_7 (line 8) - move(obj_solid);
There Code, you can use it when u want to your game its no problem:
FROG CODE
GML:
CREATE
/// @description Initialize Frog
//Set frog to be still
image_speed = 0;
image_index = 0;
sight = 70;
max_speed = 2;
acceleration = 1.5;
gravity_acceleration = 0.5;
enum frog2 {
idle,
jump
}
state = frog2.idle;
---------------------------------------------------------------------------------------------------------------
DESTROY
/// @description Destroy the frog
event_inherited();
---------------------------------------------------------------------------------------------------------------
STEP
/// @description Execute the state
switch (state) {
#region Idle State
case frog2.idle:
if (instance_exists(obj_player)) {
var dis = distance_to_object(obj_player);
if (dis < sight and alarm[0] <= 0) {
image_speed = 0.5;
if (obj_player.x != x) {
image_xscale = sign(obj_player.x - x);
}
}
}
break;
#endregion
#region Jump State
case frog2.jump:
image_index = image_number - 1;
if (!place_meeting(x, y + 1, obj_solid)) {
yspeed += gravity_acceleration;
}
else {
yspeed = 0;
apply_friction(acceleration);
if(xspeed == 0 and yspeed == 0) {
state = frog2.idle;
alarm[0] = 15;
image_speed = 0;
image_index = 0;
}
}
if (xspeed != 0) {
image_xscale = sign(xspeed);
}
move(obj_solid);
break;
#endregion
}
---------------------------------------------------------------------------------------------------------------
ALARM 0
/// @description Just needs to be here
---------------------------------------------------------------------------------------------------------------
ANIMATION END
/// @description Jump
if (state == frog2.idle) {
if (instance_exists(obj_player)) {
xspeed = sign(obj_player.x - x) * max_speed;
yspeed = -abs(xspeed * 2);
}
move(obj_solid);
state = frog2.jump;
}