GameMaker: Studio

GameMaker: Studio

View Stats:
The_Sea_Four Apr 18, 2014 @ 12:20pm
Very odd initialization error?
Hi all, I am not exactly new to GMS, but I have now found something once again that has stumped me.

I am getting the following error message upon moving to a room:

############################################################################################ FATAL ERROR in action number 4 of Step Event0 for object Peep: Push :: Execution Error - Variable Get -7.clicked(100008, -1) at gml_Object_Peep_StepNormalEvent_4 (line 2) - if (clicked=false or (x=ex and y=ey)) and ds_queue_empty(movequeue)=false ############################################################################################

Now, I know that this type of error is caused by bad initialization of a variable, but I can't seem to find anything wrong with my create event.

Looking at the compile form, it looks like the variable has been correctly initialized too.

Self Variables : Athleticism(100033) = 0.206060 fire(100103) = 0 myhealth(100039) = 1 fireindex(100104) = 0 Speech(100112) = 0.240678 ex(100048) = 560 Stealth(100113) = 0.190569 ey(100049) = 320 Invention(100114) = 0.248216 Lockpicking(100115) = 0.182450 Movement(100116) = 0.222167 Carry(100117) = 0.217124 Art(100118) = 0.229689 Food(100119) = 0.220148 Farming(100120) = 0.167826 selected(100059) = 1 rotation(100061) = 0 xfirst(100062) = 0 bleeding(100063) = 0 rarm(100064) = 1 inv(100001) = 26 larm(100065) = 1 light_surf(100129) = -200 rleg(100066) = 1 lleg(100067) = 1 injury(100068) = 1 respiratory(100069) = 1 circulatory(100070) = 1 digestive(100071) = 1 clicked(100008) = 1 ill(100072) = 0 invgui(100010) = 100305 movequeue(100144) = 0 glow(100145) = 0 selectedslot(100020) = -4 Intelligence(100086) = 0.213371 Charisma(100087) = 0.232177 j(100028) = 1 Dexterity(100031) = 0.196438

To combat this, I have renamed the variable entirely in case of spelling/typos, checked the code for duplicate variables and even run the game with everything else in the object deleted, but it still provides this error at that point.

If I move the relevant code to the create event it works fine [tested with show_message(clicked), in both step and create. Error in step.], though obviously that doesn't fix my problem. Maybe I need to post the full object code, maybe I need to cry into a pillow, or maybe you can help.
< >
Showing 1-10 of 10 comments
The_Sea_Four Apr 18, 2014 @ 12:26pm 
Relevant create event code:

///Misc Variables clicked=false show_message(clicked)

Relevant step event code:

///Tick Movement show_message(clicked) if (clicked=false or (x=ex and y=ey)) and ds_queue_empty(movequeue)=false { var tempcoords tempcoords=ds_map_create() clicked=true ds_map_read(tempcoords,ds_queue_dequeue(movequeue)) ex=ds_map_find_value(tempcoords,"x") ey=ds_map_find_value(tempcoords,"y") ds_map_destroy(tempcoords) }

The error currently occurs at the step event, on the
show_message(clicked)
line.
Pixel Prophecy Apr 18, 2014 @ 12:48pm 
I just skimmed through the code but maybe there's just a semicolon missing after the initial assignment, as in
clicked = false;
? Otherwise I can’t find any obvious mistakes at first glance either.
The_Sea_Four Apr 18, 2014 @ 12:53pm 
Hi Phil, I've never used semicolons in my code and it has never been a problem for GMC. Testing it out, it doesn't make any difference. Thanks for trying! Maybe I should send a bug report.
Pixel Prophecy Apr 18, 2014 @ 1:02pm 
Hmmm, only other thing I can think of is that your object is set to being persistent at some place?
Pixel Prophecy Apr 18, 2014 @ 1:11pm 
Hey, if you upload me a zip of a bare-bones project.folder of your problem I could take a look at it. I won’t make any promises but I’ve realized that I am way better finding bugs in other people’s code than in my own :trazz:
The_Sea_Four Apr 18, 2014 @ 1:55pm 
I am not sure how bare-bones you mean, because unfortunately my objects are all interdependant, so that may be difficult. Either way, it'll take a while to upload.

Here, have the full code of the object.

Information about object: Peep Sprite: Sprite_Front Solid: true Visible: true Depth: -1 Persistent: false Parent: mob Mask: No Physics Object Create Event: execute code: ///Inherited code event_inherited() execute code: ///Misc Variables clicked=false; show_message(clicked) selected=true selectedslot=noone //inventory slot that is currently in use //Movement ex=x ey=y rotation=0 xfirst=false movequeue=ds_queue_create() image_speed=0 execute code: ///Health variables myhealth=1 bleeding=false rarm=1 larm=1 rleg=1 lleg=1 injury=1 respiratory=1 circulatory=1 digestive=1 ill=false execute code: ///Status Effect Variables fire=false fireindex=0 glow=false execute code: ///Inventory Initialize inv=ds_grid_create(28,3) invgui=instance_create(2,display_get_gui_height()-35,Inventory_Gui) with invgui { mypeep=other.id myinv=other.inv } execute script Script_Generate_Skills with arguments (-1,,,,) Step Event: execute script depth_mob with arguments (0,0,0,0,0) execute code: ///Local light calculation //Search inventory for items that glow var i, selecteditem, currentpixel, ix, iy glow=0 if selectedslot!=noone if instance_exists(ds_grid_get(inv,selectedslot,0)) if object_is_ancestor(ds_grid_get(inv,selectedslot,0).object_index,item_parent) { selecteditem=ds_grid_get(inv,selectedslot,0) glow=selecteditem.glow } Light_Update(glow) Light_Draw(glow) execute code: ///Pause Handling if global.paused=true or global.menuopen=true { image_speed=0 exit } execute code: ///Tick Movement show_message(clicked) if (clicked=false or (x=ex and y=ey)) and ds_queue_empty(movequeue)=false { var tempcoords tempcoords=ds_map_create() clicked=true ds_map_read(tempcoords,ds_queue_dequeue(movequeue)) ex=ds_map_find_value(tempcoords,"x") ey=ds_map_find_value(tempcoords,"y") ds_map_destroy(tempcoords) } var j // If the peep is not aligned to the grid and the sqauare is not empty... if not square_empty(x,y) and (abs(ex-x)<=17 and abs(ey-y)<=17) for (j=-1; j<=1; j+=1) //if a nearby square is free, go there if square_empty(round(x/16)*16+16*j,round(y/16)*16) and irandom(1)=0 {ex=round(x/16)*16+16*j; ey=round(y/16)*16} else if square_empty(round(x/16)*16,round(y/16)*16+16*j) {ey=round(y/16)*16+16*j; ex=round(x/16)*16} //The speed of the peep is ~double the square of the ratio between the average movement skill //and that of the peep peepspeed=ceil(2*sqrt((Movement/0.20))) //If you have told the peep to move if clicked=true { if xfirst=true //and x is the larger dimention { ex=16*floor(ex/16) ey=16*floor(ey/16) //make sure the destination is on the grid. //If your x is not the destination x and you can get there in one step if x!=ex and square_empty(ex,y) and abs(x-ex)<=peepspeed x=ex //you arrive else if y!=ey and square_empty(ex,y) and abs(y-ey)<=peepspeed //If your y is not destination y and you y=ey // can get there in one step... Arrive if x!=ex //If x is still not your destination { //If the next space is free or you are clipping, go there. if (place_snapped(16,16) and square_empty(x+peepspeed*sign(ex-x),y)) or not square_empty(x,y) x+=peepspeed*sign(ex-x) else if square_empty(x+peepspeed*sign(ex-x),y) x+=peepspeed*sign(ex-x); else ex=floor(x/16)*16 //Otherwise, go to the nearest square } else if y!=ey //If y is largest dimention { //If stuck, or next space free, go there if (place_snapped(16,16) and square_empty(x,y+peepspeed*sign(ey-y))) or not square_empty(x,y) y+=peepspeed*sign(ey-y) else if square_empty(x,y+peepspeed*sign(ey-y)) y+=peepspeed*sign(ey-y); else ey=floor(y/16)*16 } else if place_snapped(16,16) //if you have arrived, reset the movement variables { xfirst=false yfirst=false clicked=false } else //otherwise, move to destination if it is close enough (failsafe) if abs(y-ey)<=peepspeed and abs(x-ex)<=peepspeed and square_empty(ex,ey) {y=ey; x=ex clicked=false } } if xfirst=false //Same again for y (I am not copying my comments!) { if y!=ey and (object_index=Peep or square_empty(ex,y)) and abs(y-ey)<=peepspeed y=ey else if x!=ex and (object_index=Peep or square_empty(ex,y)) and abs(x-ex)<=peepspeed x=ex if y!=ey { if (place_snapped(16,16) and square_empty(x,y+peepspeed*sign(ey-y))) or not square_empty(x,y) y+=peepspeed*sign(ey-y) else if square_empty(x,y+peepspeed*sign(ey-y)) y+=peepspeed*sign(ey-y); else ey=floor(y/16)*16 } else if x!=ex { if (place_snapped(16,16) and square_empty(x+peepspeed*sign(ex-x),y)) or not square_empty(x,y) x+=peepspeed*sign(ex-x) else if square_empty(x+peepspeed*sign(ex-x),y) x+=peepspeed*sign(ex-x); else ex=floor(x/16)*16 } else if place_snapped(16,16) { xfirst=false yfirst=false clicked=false } else if abs(y-ey)<=peepspeed and abs(x-ex)<=peepspeed and square_empty(ex,ey) {y=ey; x=ex clicked=false } } } else if not place_snapped(16,16) { ex=16*round(x/16) ey=16*round(y/16) clicked=true if abs(ex-x)>=abs(ey-y) xfirst=true else xfirst=false } execute code: ///Turn towards the target var target if selectedslot!=noone if instance_exists(ds_grid_get(inv,selectedslot,0)) if object_is_ancestor(ds_grid_get(inv,selectedslot,0).object_index,item_parent) if ds_grid_get(inv,selectedslot,0).itemtype='Weapon' and clicked=false if ds_grid_get(inv,selectedslot,0).Swing_Timer-ds_grid_get(inv,selectedslot,0).swing_time<=10 and instance_exists(ds_grid_get(inv,selectedslot,0).target) { target=ds_grid_get(inv,selectedslot,0).target //If the X difference is larger than the y difference if abs(x-target.x)>=abs(y-target.y) { if sign(x-target.x)=1 {rotation=270} else {rotation=90} } else { if sign(y-target.y)=1 {rotation=180} else {rotation=0} } } execute code: ///Turn for movement / animation handling if clicked=true //If the peep is going somewhere { if sign(x-xprevious)=0 and sign(y-yprevious)=1 rotation=0 if sign(x-xprevious)=1 and sign(y-yprevious)=0 rotation=90 if sign(x-xprevious)=-1 and sign(y-yprevious)=0 rotation=270 if sign(x-xprevious)=0 and sign(y-yprevious)=-1 rotation=180 image_speed=1/3 switch (rotation) { case 0: sprite_index=Sprite_Front; break case 90: sprite_index=Sprite_Right; break case 180: sprite_index=Sprite_Back; break case 270: sprite_index=Sprite_Left; break } } else //If the peep is stationary { image_speed=0 switch (rotation) { case 0: sprite_index=Sprite_Front image_index=0; break case 90: sprite_index=Sprite_Right image_index=0; break case 180: sprite_index=Sprite_Back image_index=0; break case 270: sprite_index=Sprite_Left image_index=0; break } } execute code: ///Health Tick var i, px, blood if injury>0 and respiratory>0 and circulatory>0 and digestive>0 and rarm>0 and larm>0 and rleg>0 and lleg>0 myhealth=100 * power(rarm,0.25) * power(rleg,0.25)*power(larm,0.25)*power(lleg,0.25)* power(injury,0.75) * (respiratory) * (circulatory) * power(digestive,0.3) else myhealth=0 if power(rarm,0.25) * power(rleg,0.25)*power(larm,0.25)*power(lleg,0.25)*power(injury,0.75)<0.5 for (i=10; i<=27; i+=1) { if ds_grid_get(inv,i,2)=Health_Pack { bleeding=false break } else bleeding=true } if bleeding=true { if circulatory>0 { circulatory-=0.000035 if irandom(100)=1 with instance_create(x,y,Hit_text) {text="-"} } else { circulatory=0 } } else { if circulatory<1 { circulatory+=0.000001/3 } } digestive=1 if bleeding=true { px=random_range(x+1,x+14) py=random_range(y,y+16) part_system_depth(global.sys,0) blood=part_type_create(); part_type_alpha3(blood,1,1,0) part_type_size(blood, 0.3, 0.6, 0.0025, 0); part_type_shape(blood, pt_shape_pixel); part_type_color_mix(blood, c_red, c_red); part_type_speed(blood, 1, 1, -1/16, 0); part_type_life(blood, 12, 16); part_type_direction(blood, -85, -95, 0, 0); part_particles_create(global.sys,px,py,blood,1) } if real(myhealth)<=0 { px=random_range(x+1,x+14) py=random_range(y,y+16) // The peep is dying. Have them drop their items for (i=10; i<=27; i+=1) { if ds_grid_get(inv,i,1)>0 { iteminstance=ds_grid_get(inv,i,0) { with invgui {instance_destroy()} iteminstance.x=x iteminstance.y=y iteminstance.invitem=false iteminstance.image_xscale=1 iteminstance.image_yscale=1 iteminstance.quantity=ds_grid_get(other.inv,i,1) } } } instance_create(x,y,mob_explosion) instance_destroy() } execute script script_mob_status_effects with arguments (0,0,0,0,0) exit this event execute code: ///Local light calculation //Search inventory for items that glow var i, selecteditem, currentpixel, ix, iy glow=0 if selectedslot!=noone if instance_exists(ds_grid_get(inv,selectedslot,0)) if object_is_ancestor(ds_grid_get(inv,selectedslot,0).object_index,item_parent) { selecteditem=ds_grid_get(inv,selectedslot,0) glow=selecteditem.glow } with Light_Handler surface_set_target(PEEPsurface) //if x-xprevious!=0 or y-yprevious!=0 for (ix=floor(x/16)-16;ix<=ceil(x/16)+16;ix+=1) for (iy=floor(y/16)-16;iy<=ceil(y/16)+16;iy+=1) if distance_to_point(16*ix, 16*iy)<=16*6 { currentpixel=0 //Loop through each light producing peep, and find the maximum light value { if glow!=0 { if collision_line(16*ix+8,16*iy+8,floor(x)+8,floor(y)+8,Wall,true,true)=noone or collision_point(16*ix+8,16*iy+8,Wall,true,true)!=noone currentpixel=max(currentpixel,1-sqrt(sqr(floor(x)-16*ix)+sqr(floor(y)-16*iy))/(16*glow)) } } draw_set_alpha(1) draw_set_blend_mode(bm_normal) draw_point_color(ix,iy,merge_color(c_white, c_black, 1-currentpixel)) } surface_reset_target() Mouse Event for Glob Left Released: execute code: ///Movement setting if not keyboard_check(vk_control) and global.menuopen=false if collision_point(mouse_x-view_xview[0]+view_xport[0],mouse_y-view_yview[0]+view_yport[0],GUI_Parent,false,true)=noone { var tempcoords tempcoords=ds_map_create() ds_map_add(tempcoords,"x",16*floor(mouse_x/16)) ds_map_add(tempcoords,"y",16*floor(mouse_y/16)) if not ds_exists(movequeue,ds_type_queue) movequeue=ds_queue_create() ds_queue_enqueue(movequeue,ds_map_write(tempcoords)) ds_map_destroy(tempcoords) //ex=16*floor(mouse_x/16) //ey=16*floor(mouse_y/16) if clicked=false clicked=true if abs(tempcoords[0]-x)>=abs(tempcoords[1]-y) xfirst=true else xfirst=false } execute code: ///Turn towards the mouse if collision_point(mouse_x+view_xport[0],mouse_y+view_yport[0],GUI_Parent,false,true)=noone and global.menuopen=false { //If the X difference is larger than the y difference if abs(x-mouse_x)>=abs(y-mouse_y) { if sign(x-mouse_x)=1 {rotation=270} else {rotation=90} } else { if sign(y-mouse_y)=1 {rotation=180} else {rotation=0} } } Draw Event: execute code: ///Draw status effects if fire=true draw_sprite(Sprite_Mob_Fire,fireindex,x,y) draw_self()
Pixel Prophecy Apr 18, 2014 @ 2:19pm 
thanks! well from what I can tell everything looks legit ;) Judging from your initial description, I wonder if there is a case where the step-code for the instance is being executed without the necessary creation event, which would lead to all the variables being undefined. And since "clicked" is the first one, it throws the error. For debugging reasons, have you tried calling an other variable in the step-event instead of "clicked"? Because if you get the same error, it would indicate that something’s up with the create event.

Sorry that I can't be clearer. I have not the necessary experience yet to know when or why it happens, I only know that it does sometimes.
The_Sea_Four Apr 18, 2014 @ 2:24pm 
{LINK REMOVED}

Note, that is my entire project... Lots of crap in there!

As for that, it isn't the first part of the step event, it is the first part of the execute code action. Even so, replacing it with another variable does seem to just shift the error to the next use of the variable.
Pixel Prophecy Apr 19, 2014 @ 1:30pm 
So I spent quite a while in your project (very interesting btw!!) but I am afraid I couldn’t find what’s wrong with the initialization in the Peep-object. I tried to init the object via script, manual creation event call, creating the instance via code, etc.

So after two days what do we know? We know that the error is somewhere in the Peep-object (or its parents). If you ever happen to find the bug or solve the problem otherwise, please post it here. I really want to know what’s causing it!
The_Sea_Four Apr 20, 2014 @ 5:09am 
Thanks for trying Phil! I'll probably backdate the object to a backup. I think there is some corruption in the object file, something about the step event just doesn't recognize that variable.
< >
Showing 1-10 of 10 comments
Per page: 1530 50

Date Posted: Apr 18, 2014 @ 12:20pm
Posts: 10