GML Object Variable being utterly ignored

neXasDev

Member
GML:
if state == 0 && instance_exists(ob_electron) {                        // Only if the wire is active and the the electron is present will this code run.
    var e = instance_nearest(wire_start_x, wire_start_y, ob_electron); // Assign the nearest instance a temporary variable.
    if point_in_circle(e.x, e.y, wire_start_x, wire_start_y, 4) {      // If the electron comes within a radius of 4 pixels of the wire's first vertex this code will run.
        electron_count[0] += 1;     // Electron will store itself inside the wire's first vertex's electron count (electron_count[0]).
        with(e) {                   // Electron object will destroy itself.
            instance_destroy();
        }
        // This if statement keeps returning an error. It doesn't recognize e. I have tried using e as a normal variable as well. Same problem.
    }
}
I have exhausted the better half of my day on this garbage. Please help me. It's always stupid stuff like this that completely halts my projects.
 

TsukaYuriko

☄️
Forum Staff
Moderator
Please post the error message.

I'd assume it's of the "can't find an instance for object" type, in which case no instance of ob_electron exists and your code is not safeguarded for this case via instance_exists. We'd need to see the error message to be sure, though.
 

neXasDev

Member
Please post the error message.

I'd assume it's of the "can't find an instance for object" type, in which case no instance of ob_electron exists and your code is not safeguarded for this case via instance_exists. We'd need to see the error message to be sure, though.
Here it is:

ERROR!!! :: ############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object ob_wire:


Variable <unknown_object>.y(1, -2147483648) not set before reading it.
at �z���ct_ob_wire_StepNormalEvent_1 (line 27) - if point_in_circle(instance_nearest(wire_start_x, wire_start_y, ob_electron).x, instance_nearest(wire_start_x, wire_start_y, ob_electron).y, wire_start_x, wire_start_y, 4) { ############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_ob_wire_StepNormalEvent_1 (line 27)
 

TsukaYuriko

☄️
Forum Staff
Moderator
Yup, that's not e not being recognized, but e being noone because no instance of ob_electron exists. You're therefore trying to access y of an instance that doesn't exist, which is not possible.
 

neXasDev

Member
Yup, that's not e not being recognized, but e being noone because no instance of ob_electron exists. You're therefore trying to access y of an instance that doesn't exist, which is not possible.
Why is e not being recognized? This method of assigning particular instances has worked in every other case.
 

EvanSki

Raccoon Jam Host
adding to tsuka, you also checking for ob_electron in a specific x and y then checking for it again in a circle distance but not updating that for e there for its only checking for an instance at that x and y and if its not there you get "noone"
 

neXasDev

Member
adding to tsuka, you also checking for ob_electron in a specific x and y then checking for it again in a circle distance but not updating that for e there for its only checking for an instance at that x and y and if its not there you get "noone"
How would you suggest I change the code?
 

TsukaYuriko

☄️
Forum Staff
Moderator
Why is e not being recognized? This method of assigning particular instances has worked in every other case.
As I said, it's not that e is not being recognized. This means that e is being recognized.

The problem continues to be that there is no instance of ob_electron exists at the time the code in question runs.

just update var e with what point_in_circle(e.x, e.y, wire_start_x, wire_start_y, 4) returns before checking e in the with statement
point_in_circle returns a boolean. If using the result of it in a with statement delivers expected results, it's due to sheer coincidence.
 
Top