Q
quill
Guest
I'm teaching myself game maker with a top down RPG. Problem is, i'm trying to use a script but its saying that the variable which is set in the script doesn't exist when its ran in the step event. Ill paste what I think may be relevant to the code here:
Script: scr_keyinput
///scr_keyinput
var right = (keyboard_check(ord('D')));
var left = (keyboard_check(ord('A')));
var up = (keyboard_check(ord('W')));
var down = (keyboard_check(ord('S')));
Create
phy_fixed_rotation = true;
player_spd = 4;
image_speed = 0
scr_keyinput();
Step
scr_keyinput();
//Move right
if (right) {
phy_position_x += player_spd;
sprite_index = spr_player_right;
image_speed = 0.2;
}
//Move left
if (left) {
phy_position_x -= player_spd;
sprite_index = spr_player_left;
image_speed = 0.2;
}
//Move up
if (up) {
phy_position_y -= player_spd;
sprite_index = spr_player_up;
image_speed = 0.2;
}
//Move down
if (down) {
phy_position_y += player_spd;
sprite_index = spr_player_down;
image_speed = 0.2;
}
//Stop animating
if (!down and !up and !right and !left) {
image_speed = 0;
image_index = 0;
}
As long as the reason isn't something simple i just missed, a short explanation of why the thing i did wrong needs to be as it would be when right would be appreciated, as of course I am trying to educate myself.
Thanks!
Edit: SOLVED! The problem was the "var", removed that and it worked fine! Thanks a lot!
Script: scr_keyinput
///scr_keyinput
var right = (keyboard_check(ord('D')));
var left = (keyboard_check(ord('A')));
var up = (keyboard_check(ord('W')));
var down = (keyboard_check(ord('S')));
Create
phy_fixed_rotation = true;
player_spd = 4;
image_speed = 0
scr_keyinput();
Step
scr_keyinput();
//Move right
if (right) {
phy_position_x += player_spd;
sprite_index = spr_player_right;
image_speed = 0.2;
}
//Move left
if (left) {
phy_position_x -= player_spd;
sprite_index = spr_player_left;
image_speed = 0.2;
}
//Move up
if (up) {
phy_position_y -= player_spd;
sprite_index = spr_player_up;
image_speed = 0.2;
}
//Move down
if (down) {
phy_position_y += player_spd;
sprite_index = spr_player_down;
image_speed = 0.2;
}
//Stop animating
if (!down and !up and !right and !left) {
image_speed = 0;
image_index = 0;
}
As long as the reason isn't something simple i just missed, a short explanation of why the thing i did wrong needs to be as it would be when right would be appreciated, as of course I am trying to educate myself.
Thanks!
Edit: SOLVED! The problem was the "var", removed that and it worked fine! Thanks a lot!
Last edited by a moderator: