M
Maladroit
Guest
Hello, I've been using Game Maker for several months now, and I'm using Game Maker 8.0 Lite. One problem that I've been consistently having is the "unknown variable x" error. I have 21 total objects, and I'm not merging games, so I don't think that the problem comes from issues with Game Maker confusing object indices and instance id's. The aspect of the game that this error concerns is an assistant object following the player object. This is the code within the assistant object's Step Event:
//Follow the Player
if global.pause == 0 {
if (keyboard_check_pressed(ord('L')) or distance_to_point(object_player.x + 20, object_player.y - 20) > 700) {
position_change(object_player.x, object_player.y, object_assistant, 0)
}
if (distance_to_point(object_player.x + 20, object_player.y - 20) < 50) { //this is the error line
hsp /= 1.3;
vsp /= 1.3;
} else {
hsp -= 0.001 * (x - object_player.x);
vsp -= 0.001 * (y - object_player.y);
}
When I run the game, I receive an error as such:
ERROR in
action number 1
of Step Event
for object object_assistant:
Error in code at line 9:
if (distance_to_point(object_player.x + 20, object_player.y - 20) < 50) {
^
at position 42: Unknown variable x
If I forgot to mention anything or if I wasn't specific enough about something, please tell me (sorry in advance). Thanks.
//Follow the Player
if global.pause == 0 {
if (keyboard_check_pressed(ord('L')) or distance_to_point(object_player.x + 20, object_player.y - 20) > 700) {
position_change(object_player.x, object_player.y, object_assistant, 0)
}
if (distance_to_point(object_player.x + 20, object_player.y - 20) < 50) { //this is the error line
hsp /= 1.3;
vsp /= 1.3;
} else {
hsp -= 0.001 * (x - object_player.x);
vsp -= 0.001 * (y - object_player.y);
}
When I run the game, I receive an error as such:
ERROR in
action number 1
of Step Event
for object object_assistant:
Error in code at line 9:
if (distance_to_point(object_player.x + 20, object_player.y - 20) < 50) {
^
at position 42: Unknown variable x
If I forgot to mention anything or if I wasn't specific enough about something, please tell me (sorry in advance). Thanks.