This is my first question on a forum so please forgive any mistakes I may have made.
I am trying to make a game similar to the classic "Asteroids". I am trying to split the asteroids in two when a laser hits them. The following code is in an event in the asteroid object that is triggered when the laser collides with the asteroid.
inst1 = instance_create(x, y, medium1)
with (inst1) {
speed = random_range(5,8)
direction = laser.direction + random_range(0, 90)
}
inst2 = instance_create(x, y, medium1)
with (inst2) {
speed = random_range(5,8)
direction = laser.direction - random_range(0 ,90)
}
My issue occurs seemingly randomly. The game loads normally and the asteroids will split several times (sometimes 3-4, sometimes I can almost go through an entire game without encountering it) as I want them to, then this error pops up.
ERROR in
action number 1
of Collision Event with object laser
for object big1:Error in code at line 4:
direction = laser.direction + random_range(0, 90)
^
at position 26: Unknown variable direction
Any suggestions on how to fix this issue? Thank you very much in advance!
laser? A variable or an object's name? \$\endgroup\$