• 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!

Error with deactivating object

S

salt

Guest
Hello!
I started to use this so that my game would run smoother:

instance_deactivate_region(view_xview-64,view_yview-64,view_wview+128,view_hview+128,0,1)
instance_activate_region(view_xview-32,view_yview-32,view_wview+64,view_hview+64,1)

The only problem is that I have a water object that makes the game crash for some reason after I started using the code above. This is the error message that pops up.
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event2
for object obj_water:

Push :: Execution Error - Variable Index [0,35] out of range [1,35] - -1.wY(100140,35)
at gml_Object_obj_water_StepEndEvent_1 (line 28) - wY = mean(wY,wY,wY,wY[i-1],wY[i+1])
############################################################################################

I have no idea what is going wrong please help me. Thanks!
 
S

salt

Guest
This is the entire code for my water object. Sorry if its a lot. :/

create event:
///Setup
waterColor = merge_color(c_blue,c_aqua,.3)
disturbance = 1
//-1 = small 1=large
if global.waterscale = -1
{
image_xscale *= 4.5
image_yscale *= 3
}
if global.waterscale = 1
{
image_xscale *= 8.7
image_yscale *= 2
}
for(i=0;i<=image_xscale*4;i+=1)
{
wY = 0
vspd = 0
}

End step event:
///Update

if distance_to_point(obj_player.x,y) < 650
{
scr_waterreact()


repeat(disturbance*image_xscale)
{
vspd[irandom(image_xscale*4)] += choose(.4,-.4)
}

for(i=0;i<=image_xscale*4;i+=1)
{
vspd = max(min(vspd,32),-32)

wY += vspd
wY = max(min(wY,32),-32)

vspd -= wY*.1

if i = image_xscale*4 || i = 0 || position_meeting(x+(i-1)*8,y-1,obj_water) || position_meeting(x+(i+1)*8,y-1,obj_water) || position_meeting(x+i*8,y-1,obj_solid)
{
wY = 0
}
else
{
wY = mean(wY,wY,wY,wY[i-1],wY[i+1])
}
}

}

draw:

draw_set_color(waterColor)
draw_primitive_begin(pr_trianglestrip)
for(i=0;i<=image_xscale*4;i+=1)
{
if i == 0 || i == image_xscale*4
{
draw_set_alpha(0)
}
else
{
draw_set_alpha(.4)
}
draw_vertex(x+i*8,bbox_bottom+1)
draw_vertex(x+i*8,y+wY)
}
draw_primitive_end()

draw_set_color(c_white)
draw_primitive_begin(pr_trianglestrip)
for(i=0;i<=image_xscale*4;i+=1)
{
draw_set_alpha(0)
draw_vertex(x+i*8,y+wY+1)
draw_set_alpha(-wY*10)
draw_vertex(x+i*8,y+wY)
}
draw_primitive_end()
draw_set_alpha(1)

scr_waterreact():

//water disturbance when hit by object
with instance_place(x,y,obj_player)
{
if bbox_bottom <= other.y+32
{
xPlace = round((x-other.x)/8)
if xPlace >= 0 && xPlace <= other.image_xscale*4
{
other.vspd[xPlace] += vspd/2
}
for(i=1;i<abs(round(vspd));i+=1)
{
if xPlace-i >= 0 && xPlace-i <= other.image_xscale*4
{
other.vspd[xPlace-i] += (vspd/2)-sign(vspd)*i*1.5
}
if xPlace+i >= 0 && xPlace+i <= other.image_xscale*4
{
other.vspd[xPlace+i] += (vspd/2)-sign(vspd)*i*1.5
}
}
}
}
 
I don't think you meant to do this:

Code:
for(i=0;i<=image_xscale*4;i+=1)
{
wY = 0
vspd = 0
}
that just sets wY and vspd to 0 a bunch of times. You're probably trying to initialize an array to zero, right? But then again I'm confused because you use wY in some places as if it is not an array. And then I just read your initial error message, were you use wY as an array and a real value in the sime line.
 
Last edited:

RangerX

Member
Hello!
I started to use this so that my game would run smoother:
instance_deactivate_region(view_xview-64,view_yview-64,view_wview+128,view_hview+128,0,1)
instance_activate_region(view_xview-32,view_yview-32,view_wview+64,view_hview+64,1)
One thing I find odd in your code. Why deactivating a region 64 pixels larger than your view and then activating a region of 32 pixel larger than the screen?
I mean its ok to activate a region slightly larger than the screen but then you want the rest to be deactivated outside of that.
 
S

salt

Guest
One thing I find odd in your code. Why deactivating a region 64 pixels larger than your view and then activating a region of 32 pixel larger than the screen?
I mean its ok to activate a region slightly larger than the screen but then you want the rest to be deactivated outside of that.
What do you mean? How would I do that?
 

RangerX

Member
What you seem to have now is this:

You have a room (everything is loaded in it and active).
Then you deactivate a zone that is 64 pixel wider than the view.
Then you activate a zone that is 32 pixel wider than the view.



Basically your room active, there's just a small strip of objects that are deactivated outside. (green is activated, peach is deactivated)
What you want though, well, at least that you SHOULD want if you want to really speed up is this:

The room totally deactivated except a region that is 32 pixel wider than the view...




Now to achieve this here's what you should do:

- When the room start, skip a few steps and deactivate everything except you object responsible to activate what's on screen.
- Have your object responsible for activation to activate that 32 pix wider zone every step.
- All object exiting that zone should deactivate themselves (because if you deactivate the whole room every step it will be a huge toll on the engine and will not be worth it)
 
I

icuurd12b42

Guest
The more accurate confusion is you are deactivating within the view passing 1 as the inside argument... and reactivating within the view. So the only stuff active is outside the view

did you not mean to deactivate everything outside the view, you need to pass 0 as "inside" argument then reactivate inside the view, passing 1?

instance_activate_region
instance_deactivate_region
 
I

icuurd12b42

Guest
the error mean you are accessing an array[] out of its allocated size

like you have 2 items in arr[] . arr[0] is valid, arr[1] is valid.. arr[2] is out of range. arr[-1] is also out of range and invalid
 
I

icuurd12b42

Guest
arr[0] = 1;
show_debug_message(arr[1]);
Variable Index [0,1] out of range [1,1]

arr[0] = 1;
show_debug_message(arr[2]);
Variable Index [0,2] out of range [1,1]

arr[0] = 1;
arr[2] = 1;
arr[3] = 1;
arr[4] = 1;

show_debug_message(arr[5]);
Variable Index [0,5] out of range [1,5]

Variable Index [0,35] out of range [1,35]
The number are not really obvious... It's worst if the array is 2d but looks to me this error is saying you are trying to access arr[35] in a 35 size array where the last item is [34]
 
S

salt

Guest
Everyone has been very helpful in helping me to understand the problem but I feel like I've tried everything and it still doesn't work. Are there any other methods to more effectively make my game run smoother? I already have it so objects out of view are not drawn but there are still major framerate issues.
 

Yal

šŸ§ *penguin noises*
GMC Elder
It takes a while to activate and deactivate objects, so I'd do it in an alarm instead of every step. (Iji does it every 8 steps, for instance; I usually use between 4 and 10 steps depending on how fast-paced the game is). I'd set the alarm to 1-2 steps the first time to make sure it gets called as soon as possible, though.

Make sure to check out the game in debug mode. First of all check that the instance counter goes down once deactivation starts, secondly the debug overlay has bars representing things like instance code processing, draw processing, and texture swaps... check which one is the longest (= most CPU usage) and then look into ways to improve that; it's often easier to fix whatever's the least efficient than to improve something that's more efficient even more. The squeaky wheel gets the oil, you know.
 
S

salt

Guest
the step event is using the most cpu usage in the debugger. Is there anyway to deactivate it when it's not being used?
 
I

icuurd12b42

Guest
the step event is using the most cpu usage in the debugger. Is there anyway to deactivate it when it's not being used?
By making it an alarm event instead so you can tweak how many times it gets called
 
S

salt

Guest
I fixed it by creating an object that was a placeholder for the water object and destroyed the water when the player was too far away and created a new one when the player got close. Thank you everyone for saving my game it runs very smoothly now!
 

Yal

šŸ§ *penguin noises*
GMC Elder
Don't forget to mark your topic as solved if your problem is solved~ā™«
 
Top