GML Game Crash On Collision with List Functions

W

Wretched.Dunce

Guest
I'm making an asteroids-like shooter and I'm currently trying to get the speed value of an object before collission and calculate the "push back". I'm not using the built in physics engine cause I guess I hate myself, lol.
However whenever two objects collide the game crashes saying "obj_enemy.speedometer not set before reading".
For physical objects that can collide I have created a parent group that detects collissions and reacts. Heres the code for those objects:
Create Event:
Code:
speedometer = ds_list_create();
ds_list_clear(speedometer);
Step Event:
Code:
ds_list_add(speedometer, image_speed)
if ds_list_size(speedometer) >= 3
{
    ds_list_delete(speedometer, 0)
}
Collission with same parent_object:
Code:
with (other)
    {
        hp -= 1;
    }
speed = 0;
motion_add(point_direction(x, y, other.x, other.y), -0.5 * ds_list_read(speedometer, "0", " "));

Thank you for the help!
 
W

Wretched.Dunce

Guest
You should read up on what ds_list_read does.
I think what you're looking for is ds_list_find_value. (Or you could use an accessor)
whoops, you’re right! Thanks for the help

You should read up on what ds_list_read does.
I think what you're looking for is ds_list_find_value. (Or you could use an accessor)
I've changed the scripting, but I still get the same error
here's the changed code
Step Event:
Code:
ds_list_add(speedometer, speed)
if ds_list_size(speedometer) >= 2
{
    ds_list_delete(speedometer, 0)
}
Collision Event:
Code:
with (other)
    {
        hp -= 1;
    }
collisionspeed = speedometer[| 1];
speed = 0;
motion_add(point_direction(x, y, other.x, other.y), -0.5 * collisionspeed);
 
Top