P
PetrifiedPenguin
Guest
So I'm brand new to programming and even newer to GML language. I'm making a game in which the player dodges traffic as the player speeds down a 4 lane highway in a small car.
I have a step event that is supposed to check if a vehicle has passed the bottom of the room (being a y value of 800) and place it back at the top of the room, then run a loop that picks a random lane, checks that the lane isn't occupied by another vehicle already and then place that vehicle in the chosen lane (essentially picking and assigning the x value).
If the lane IS occupied it should continue the loop until it finds a free lane. This is my script so far:
So this KIND OF works. It finds a lane and assigns it but every time it runs, the game stutters as though it freezes for a second, occasionally a vehicle will be assigned to a lane that isn't free so 2 vehicles will share the same space and eventually the game will freeze.
So the question is, is there an easier way to do this? And why am I having issues? Keeping in mind I'm VERY new to programming so you might have to be patient and break it down for me.
Thanks very much for any help in advance
I have a step event that is supposed to check if a vehicle has passed the bottom of the room (being a y value of 800) and place it back at the top of the room, then run a loop that picks a random lane, checks that the lane isn't occupied by another vehicle already and then place that vehicle in the chosen lane (essentially picking and assigning the x value).
If the lane IS occupied it should continue the loop until it finds a free lane. This is my script so far:
Code:
if y >= 800
{
rep = true
y = -48
while rep = true
{
{
lanePick = random_range(1,5)
}
if lanePick == 1 and !collision_line(lane1x, -96, lane1x, 0, obj_veh, false, false)
{
x = lane1x
rep = false
show_debug_message("1")
}
if lanePick == 2 and !collision_line(lane2x, -96, lane2x, 0, obj_veh, false, false)
{
x = lane2x
rep = false
show_debug_message("2")
}
if lanePick == 3 and !collision_line(lane3x, -96, lane3x, 0, obj_veh, false, false)
{
x = lane3x
rep = false
show_debug_message("3")
}
if lanePick == 4 and !collision_line(lane1x, -96, lane1x, 0, obj_veh, false, false)
{
x = lane4x
rep = false
show_debug_message("4")
}
}
}
So the question is, is there an easier way to do this? And why am I having issues? Keeping in mind I'm VERY new to programming so you might have to be patient and break it down for me.
Thanks very much for any help in advance