• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code Code Error

G

GriffinTGA

Guest
Hello! So I have recently started working on GameMaker Studio 2, and I was following HeartBeast's tutorial on grabbing onto ledges, and I came across an error that wouldn't let me start the game. The error said this:

Script: scr_move_state at line 68 : unknown function or script position

So here is the scr_move_state code.

///scr_move_state

var rkey = keyboard_check(vk_right);
var lkey = keyboard_check(vk_left);
var jkey = keyboard_check(vk_up);

// Check for ground
if (place_meeting(x, y+1, obj_platform)) {
vspd = 0;

// Jumping
if (jkey) {
vspd = -jspd;
}
} else {
// Gravity
if (vspd < 10) {
vspd += grav;
}
}

// Moving right
if (rkey) {
hspd = spd;
}

// Moving left
if (lkey) {
hspd = -spd;
}

// Check for not moving
if ((!rkey && !lkey) || (rkey && lkey)) {
hspd = 0;
}

var moving_right = sign(hspd);

// Horizontal collisions
if (place_meeting(x+hspd, y, obj_platform)) {
while (!place_meeting(x+sign(hspd), y, obj_platform)) {
x+= sign(hspd);
}
hspd = 0;
}

// Move horizontally
x+= hspd;

// Vertical collisions
if (place_meeting(x, y+vspd, obj_platform)) {
while (!place_meeting(x, y+sign(vspd), obj_platform)) {
y+= sign(vspd);
}
vspd = 0;
}

// Move vertically
y += vspd;

// Collisions end
var was_free = !position(x+(16*moving_right), yprevious, obj_platform);
var is_not_free = position_meeting(x+(!16*moving_right), y, obj_platform);
var moving_down = yprevious < y;

if (was_free && is_not_free && moving_down) {
hspd = 0;
vspd = 0;
state = scr_ledge_grab_state;
}

// Control the sprites
if (yprevious != y) {
sprite_index = spr_jump;
image_speed = 0;
image_index = y>yprevious;
} else {
if (xprevious != x) {
sprite_index = spr_walk;
image_speed = 1;
} else {
sprite_index = spr_stand;
}
}

// Control the direction of the player facing
if (xprevious < x) {
image_xscale = 1;
} else if (xprevious > x) {
image_xscale = -1;
}

And here is the scr_ledge_grab_state:

///scr_ledge_grab_state()
var jkey = keyboard_check_pressed(vk_up);
var dkey = keyboard_check(vk_down);

if (jkey) {
vspd = -jspd;
state = scr_move_state;
}

if (dkey) {
state = scr_move_state;
}

Can any of you help me fix it? :D
 

gnysek

Member
You have directly wrote what's wrong in above error.

On line 68, there's a function position used which is unknown for game.

Code:
var was_free = !position(x+(16*moving_right), yprevious, obj_platform);
Probably there should be position_meeting here, looking for other lines of code.

However, this topic should be in this forum - https://forum.yoyogames.com/index.php?forums/programming.13/ - as it's not a GMS2 bug, but your bug in code. Please don't copy and paste doesn't even looking into content, as this is very bad, and you never learn anything.

P.S. there's [ code ] tag on forums, so you can use it to format code a little ;)
 
Top