B

#### BlazingMuffinz

##### Guest

Code:

```
FATAL ERROR in
action number 1
of Step Event0
for object obj_Hero:
trying to index a variable which is not an array
at gml_Script_InFloor (line 10) - var thefloor = global.heights[(argument1 mod TILE_SIZE) + (pos * TILE_SIZE)];
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_InFloor (line 10)
called from - gml_Object_obj_Hero_Step_0 (line 66) - var floordist = InFloor(tilemap,x,bbox_bottom+vsp);
```

I'm pretty new to this (I'd like to think I'm more of a designer than a programmer) so I don't really understand what its saying. I looked on lines 10 and 66 and couldn't find anything wrong. Help would be greatly appreciated!

My original code for obj_Hero:

Code:

```
var p1,p2,bbox_side;
//Get Player Input
key_left = keyboard_check(ord("A"));
key_right = keyboard_check(ord("D"));
key_up = keyboard_check(ord("W"));
key_down = keyboard_check(ord("S"));
key_jump = keyboard_check_pressed(vk_space);
key_jump_held = keyboard_check(vk_space);
//Calc Movement
hsp = (key_right - key_left) * walksp;
vsp += grv
//is my middle center touching the floor at the start of theis frame
var grounded = (InFloor(tilemap,x,bbox_bottom+1) >= 0);
//Jump
if (grounded || (InFloor(tilemap,bbox_left,bbox_bottom+1) >= 0) || (InFloor(tilemap,bbox_right,bbox_bottom+1) >= 0))
{
if (key_jump)
{
vsp = SPD_JUMP
grounded = false
}
}
//Re apply fractions
hsp += hsp_fraction;
vsp += vsp_fraction;
//Store and Remove Fractions
hsp_fraction = hsp - (floor(abs(hsp)) * sign(hsp));
hsp -= hsp_fraction;
vsp_fraction = vsp - (floor(abs(vsp)) * sign(vsp));
vsp -= vsp_fraction;
//Horizonal Collision
if (hsp > 0) bbox_side = bbox_right; else bbox_side = bbox_left;
p1 = tilemap_get_at_pixel(tilemap,bbox_side+hsp,bbox_top);
p2 = tilemap_get_at_pixel(tilemap,bbox_side+hsp,bbox_bottom);
if (tilemap_get_at_pixel(tilemap,x,bbox_bottom) > 1) p2 = 0;
if (p1 == 1) || (p2 == 1) //Inside tile with collision
{
if (hsp > 0) x = x - (x mod TILE_SIZE) = (TILE_SIZE-1) - (bbox_right - x);
else x = x - (x mod TILE_SIZE) - (bbox_left - x);
hsp = 0;
}
x += hsp;
//Vertical Collision
if (tilemap_get_at_pixel(tilemap,x,bbox_bottom+vsp) <= 1)
{
if (vsp > 0) bbox_side = bbox_bottom; else bbox_side = bbox_top;
p1 = tilemap_get_at_pixel(tilemap,bbox_left,bbox_side+vsp)
p2 = tilemap_get_at_pixel(tilemap,bbox_right,bbox_side+vsp)
if (p1 == 1) || (p2 == 1) //Inside tile with collision
{
if (vsp >= 0) y = y - (y mod TILE_SIZE) + (TILE_SIZE-1) - (bbox_bottom - y);
else y = y - (y mod TILE_SIZE) - (bbox_top - y);
vsp = 0;
}
}
var floordist = InFloor(tilemap,x,bbox_bottom+vsp);
if (floordist >= 0)
{
y += vsp;
y -= (floordist +1);
vsp = 0
floordist = -1;
}
y += vsp;
//Walk down slopes
if (grounded)
{
y += abs(floordist)-1;
if ((bbox_bottom mod TILE_SIZE) == TILE_SIZE-1)
{
//if the slope continues
if (tilemap_get_at_pixel(tilemap,x,bbox_bottom+1) > 1)
{
//move there
y += abs(InFloor(tilemap,x,bbox_bottom+1));
}
}
}
//Dynamic Jump Height
if (vsp > 0) && (!key_jump_held) vsp = max(vsp,0);
```

Code:

```
var pos = tilemap_get_at_pixel(argument0,argument1,argument2)
if (pos > 0)
{
if (pos == 1) return (argument2 mod TILE_SIZE);
var thefloor = global.heights[(argument1 mod TILE_SIZE) + (pos * TILE_SIZE)];
return ((argument2 mod TILE_SIZE) - thefloor);
} else return -(TILE_SIZE - (argument2 mod TILE_SIZE));
```