• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Does Draw event run before Create? (Resolved)(Thanks Arconious)

S

Selva

Guest
So. Related to a recent thread, but slightly different. Again, thank you all for being patient with me.

I'm initializing a variable in the "create" event of an instance. It is to be checked in the "draw" event. This seems like it aught to work. But I am getting an error that says the array does not exist. Code follows:

"Create" Event:
Code:
var vIndex;

for (vIndex = 0; vIndex < 10; vIndex += 1)
{
    My_Destination_AR[vIndex, 0] = false;  // Instance ID of Destination
    My_Destination_AR[vIndex, 1] = false;  // Is this location connected?
}
"Draw" event:
Code:
draw_self();
var vMy_Dest;

if My_Destination_AR[1, 1] = true    //<-----Error occurs here.   - Selva
then
{   
    vMy_Dest = My_Destination_AR[1, 0]
    draw_arrow(x,y, vMy_Dest.x, vMy_Dest.y, 1 );
}



if global.Player_Location = id
then draw_sprite(SPM_Player, -1, x+20, y+20);
Sadly, the technique from my previous thread will not work here (<Thanks again to both Nocturne and NightFrost>) as these are local arrays. It seems as if the "Draw" event is running before the "Create" event. But I know that shouldn't be happening. So what am I missing?

Thanks in advance for any clues.
- Selva
 
B

brokenjava

Guest
The draw event is AFTER the create event.

Game maker assignment vs evaluation ????????????? Thanks for the ambiguity Game maker.


if My_Destination_AR[1, 1] = true
try
if ( My_Destination_AR[1, 1] == true ){

vMy_Dest = My_Destination_AR[1, 0]
draw_arrow(x,y, vMy_Dest.x, vMy_Dest.y, 1 );
}

if ( global.Player_Location == id ) draw_sprite(SPM_Player, -1, x+20, y+20);

if that don't work fire up the debugger and find out whats going wrong?

can you post the error?

draw_arrow(x,y, vMy_Dest.x, vMy_Dest.y, 1 );

vMy_Dest.x,
how is that supposed to work?
 
A

Arconious

Guest
Could you post the exact error? Is that the entire create event? I know you mentioned it was saying "array does not exist", but if your code is exactly as shown, I'm not immediately seeing why the array is being indicated as not existing.

Also, if your first comparison in the draw event, make sure to use "==" instead of "=" if you aren't already aware!
 
B

brokenjava

Guest
{ vMy_Dest = My_Destination_AR[1, 0] draw_arrow(x,y, vMy_Dest.x, vMy_Dest.y, 1 ); }
the local var vMy_Dest is true or false it does not have an x or y component. That's my bet.
 
S

Selva

Guest
Okay. The events were cut and pasted into the "insert window." I admittedly truncated the first two comment lines that are automatically placed there by GMS2. I also inserted the "//error occurs here" bit. I am ->relatively<- sure that these are inconsequential, but I can re-post them in their unedited entirety if needed ...they won't be in color. I tried shifting to "==" form "=". I have been told that using "==" as a comparater as opposed to "=" is optional. I tend to use "=" because I am used to it and get confused with the "==" on occasion. (Yes. Dino brain. "Necromancy inside" is on my baseball caps.) However, there was no difference with either number of ='s used. 1 or 2. So, I'm not thinking that is the issue. The current set up is a holding pattern for checking the entire array in the planned game. I would not think, however, that you would need an array to recieve a single array... um... datum? (The data at array coords [x, y] is being transferred to vMy_Dest, not the entire array. So vMy_Dest shouldn't need to be an array. Should it? Please correct me if I'm wrong there.)

Here is a copy->paste of the error as requested. Apologies for the delay in reply. Today has been chaotic IRL.

___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Draw Event
for object PT_Map_Locations:

trying to index a variable which is not an array
at gml_Object_PT_Map_Locations_Draw_0 (line 8) - if My_Destination_AR[1, 1] = true
############################################################################################
 
K

Kenjiro

Guest
Hibba dibba da dibba do.
 
Last edited by a moderator:
S

Selva

Guest
Yup. Though technically, the object is a Parent type object.
 
S

Selva

Guest
And, yes. I have double checked. The only child object that has any code in it uses the event inherited function first thing. So this should not be an issue.
 
A

Arconious

Guest
So I created a test project copying over the code you provided (alongside some small changes to fill the array and to output text instead of an arrow for testing). It worked without issue for me -- I even tested with a child object.

So there must be more to this equation -- what objects are involved in this process, if any? Are you getting/setting the My_Destination_AR array in any other code?
 
B

brokenjava

Guest
EDIT: sorry i'm a dummy you get the id from the array derp. so that means you have to check if an instance exists instance_exists( vMy_Dest )




comment out
draw_arrow(x,y, vMy_Dest.x, vMy_Dest.y, 1 );

if no error is thrown that means the following
vMy_Dest.x <-- there is no .x component

the value in the array should be true or false not a "REAL" or a member variable.

If you can use the yyc compiler it will probly give you a different error line number.

OR use a breakpoint F9 on the if statement "Line 8" and press F6 to start the debugger. when your code reaches that line you can see what happens Press F11 or F10 to jump in! The error Line given most likely is not the problem, since the loacl var

vMy_Dest = My_Destination_AR[1, 0]

is going to be true or false.
 
Last edited by a moderator:
S

Selva

Guest
Acronius: There are two other objects involved. the first has no events of it's own. The second has the following:

"Create" event
Code:
global.Player_Location = id;
"Draw" event:
Code:
event_inherited();

draw_self();
Again, I truncated the automatic comment lines. Otherwise this is cut and paste.
Technically the game has only one other object but it is unused at this point. (No instances ever exist.)
Curiously, if I delete the "Create" event the game runs without error.


Brokenjava: I am in the process of checking the items you have suggested. But that is taking a bit of time and I am having unrelated issues IRL limiting my PC time today. 8(
I appreciate your patience with me. If I had more skill with this sort of thing I'd... have a different life. Also,I am somewhat ashamed to admit. I'm not sure what the "yyc" compiler is. Is that new to GM:S2?
 
A

Arconious

Guest
Is that the 'Create' event of the child object? If so, then I see the problem: you need to call event_inherited() in there as well!

I believe you're already aware of this, but just for sake of reiterating it: That function has to be put in every event you want inherited *IF* you have other code you intend to run. Otherwise the default is as you expects; it automatically runs the parent's code. The moment you add your code though, you also need to call event_inherited at some point.

This would be consistent with the error, as it was just saying it had no idea what the My_Destination_AR is.
 
Last edited by a moderator:
S

Selva

Guest
*Grumble* It's always something painfully obvious. Thank you very much for spotting that. 8)

-PS I'm a twit.
 
Top