///Check collision line - guy
var g;
if passenger = noone {
g = collision_line(x, y, ropebridgestation_left.x, ropebridgestation_left.y, guy, false, false)
show_debug_message(string(g) + " -- " + string(instance_exists(g)))
if g != noone {
if g.x > ropebridgestation_left.x and g.x < x {
passenger = g
g.onrope = true
}
}
}
(sorry for the missing indentation, blame the forum software)
The code is executed from ropebridgestation_right. There is an instance in the room of ropebridgestation_left and I want to check collision on the line between the two stations for characters (object name guy).
If you ask me, this is correct code.
I run my game in Windows C++ runner, and as soon as one of the characters crosses the bridge the game simply shuts down itself. The console form states this:
You see a bunch of debug messages and then the error I don't understand. -4 is noone, the output of collision_line when there is no collision. The 0 tells me that indeed, instance_exists(noone) is false. That explains the -4 -- 0.-4 -- 0
-4 -- 0
-4 -- 0
-4 -- 0
100954 -- 0
############################################################################################
VMError!! Occurred - Push :: Execution Error - Variable Get x
at Object.ropebridgestation_right.Step.0 (line -1) - <unknown source line>
############################################################################################
Local Variables :
100119( g ) = 100954.000000
Then the collision occurs. The g in the above code becomes an instance id, here 100954. I have checked that this is indeed the id of the colliding guy (debugger says so). In fact it is an instance of another object that has guy as the parent object. This should not matter, because the id is correct, so collision_line works correctly on the parent object. However, instance_exists(100954) return false! That explains why "g.x" bugs out, But why!?!? is instance_exists(100954) false if 100954 is clearly the id of an existing instance?
In the original code of course I don't like the "g != noone". I prefer if instance_exists(g). But if I use that, simply nothing happens, because instance_exists keeps returning false.
Anyhow. My guess was that instance_exists is not working here. So I ran a little test to see if instance_exists works correctly. I set up a simple test sample containing two objects. One looks for collisions on the other. The code in the test controller:
var g;
if passenger = noone {
g = collision_line(x, y, mouse_x, mouse_y, object0, false, false)
show_debug_message(string(g) + " -- " + string(instance_exists(g)))
if g != noone {
if g.x > x {
passenger = g
}
}
}
Looks like pretty much the same code to me.
The compile form:
What? The bug is not in instance_exists? Why suddenly now it does work, and why doesn't it in my actual game?-4 -- 0
-4 -- 0
-4 -- 0
-4 -- 0
-4 -- 0
100002 -- 1
I have only one question.
What is going on?!?











