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

Legacy GM instance_activate not working properly

7

7bones

Guest
Hi.

I have activate/deactivate code for optimise my game
All works in alarm event of player

"
if (global.processing=false){
instance_deactivate_region(view_xview[0] - 428, view_yview - 428, view_wview[0] + 892, view_hview[0] + 892,false, true);
instance_activate_object(obj_checkpoint_saver)


instance_activate_region(view_xview[0] - 428, view_yview - 428, view_wview[0] + 892, view_hview[0] + 892, true);
alarm[7]=30

}
if (global.processing=true){instance_activate_region(view_xview[0] , view_yview , view_wview[0] , view_hview[0] ,false)

"

It works very good and make stable 60fps with a lot of objects in room
But here is problem.Save and load system.

When player touch checkpoint place

In obj_checkpoint collision with player event (examle script,all info are saved there also)

"
global.processing=true
instance_activate_all()
with obj_blood_parent {event_user(0)} /////makes obj_blood_parent.save=true


"
When player dies :
"
global.processing=true
instance_activate_all()
with obj_blood_parent {event_user(1)} /////if obj_blood_parent.save=false it destroy self

"
This type I used to all (blood_parent is only example) variables and objects

Problem is instance_activate_all() not working, also instance_activate_region(view_xview[0] , view_yview , view_wview[0] , view_hview[0] ,false) not working and even instance_activate_object is not working.
Event_user(0) when save works ONLY when objects are in range of activate_region of player,cannot activate it .I can do
"
if (global.processing=false){
instance_deactivate_region(view_xview[0] - 428, view_yview - 428, view_wview[0] + 892, view_hview[0] + 892,false, true);
instance_activate_object(obj_checkpoint_saver)

instance_activate_obj(obj_blood_parent)

instance_activate_region(view_xview[0] - 428, view_yview - 428, view_wview[0] + 892, view_hview[0] + 892, true);
"
And then works fine- but that is not optimization,getting slow very fast...

Where i made something wrong??
 
M

MishMash

Guest
Right, this post is a little difficult to read, but I have picked out a few bits of interest:

1) instance_activate_region(view_xview[0] , view_yview , view_wview[0] , view_hview[0] ,false)
Here you set the "inside" argument to false, which means it will activate everything outside that region (and not the things inside), did you intend to do this?

2) Put show_debug_message("..."); commands after the lines of interest (such as instance_activate_all()) to verify that those lines are being executed when you expect them to be. If you stick these in every time your deactivation checks run, you can easily analyse the flow of your code.

3) It also appears that the alarm[7] only gets reset in the case where "if (global.processing=false)", meaning it will not subsequently keep on running?
 
7

7bones

Guest
Thx.Hard to read,i know ,but that is large case :/

Ill try simplier
1.Have code that deactivate region outside view
2.Saving on checkpoint activate ALL instances for while -but that NOT working- can save only instances in view.But activate seems to work (i used code to show number of instances in room- before activate shows about 300 after show about 2000 for while- so it happening)
3.If I wont use deactivate code - saving system works perfect...
What is wrong? Here is again that code (i used variable global.processing to make sure it wont work while saving-but nothing changed)

///OPT
alarm[7]=30

if (global.processing=false){
instance_deactivate_region(view_xview[0] - 428, view_yview - 428, view_wview[0] + 892, view_hview[0] + 892,false, true);
instance_activate_object(obj_checkpoint_saver)



instance_activate_region(view_xview[0] - 428, view_yview - 428, view_wview[0] + 892, view_hview[0] + 892, true);


}
if (global.processing=true){instance_activate_region(view_xview[0] , view_yview , view_wview[0] , view_hview[0] ,false)
instance_activate_region(view_xview[0] , view_yview , view_wview[0] , view_hview[0] ,true)


}

I also used instance_activate_all in every line before saving- still no working
 
M

MishMash

Guest
First of all, you can format your forum posts using a code box, makes it easier to read code rather than lumping text and code together.
Code:
example
Again, please consider adding show_debug_message("...") calls to your code so you can see what code is and isn't running. Clearly there is going to be a logic flaw somewhere, it's not going to be a bug with GM and getting into a habit of putting these in your code will help you analyse your code by seeing what control path is followed, and if you use show_debug_message to output values, you can see what the state of variables is at each given instance.

For example, you might be able to deduce that the object that runs the save code is itself deactivated by placing a show_debug_message after your call to instance_activate_all()
It seems to me that in any case, regardless of whether global.processing is true or false, you should be activating obj_checkpoint_saver, no?

Try this:
Code:
///OPT
alarm[7]=30
instance_activate_object(obj_checkpoint_saver)

show_debug_message("Running activation code");
if (global.processing=false){
    instance_deactivate_region(view_xview[0] - 428, view_yview - 428, view_wview[0] + 892, view_hview[0] + 892,false, true);
  
    instance_activate_region(view_xview[0] - 428, view_yview - 428, view_wview[0] + 892, view_hview[0] + 892, true);
}
if (global.processing=true){
    //instance_activate_region(view_xview[0] , view_yview , view_wview[0] , view_hview[0] ,false)
    //instance_activate_region(view_xview[0] , view_yview , view_wview[0] , view_hview[0] ,true)
    instance_activate_all();
}
Can you also please elaborate on what the global.processing variable is for? I'm guessing that when it is active, you want everything to be activated, right? If so, i'd suggest replacing the two lines corresponding to activating inside and outside of a region to an instance_activate_all() just to be sure.

Also, with your views, you are using view_xview[0], but are using view_yview (without any access indicator). If you have multiple views, this will default to whichever view is the "main" one "view_current". Whilst it shouldn't matter, its best to be consistent.

With the code I posted above, what you should see are repeated "Running activation code" messages appearing in the console. if you do not, then the code is not running.

I'm also making the assumption that the code you are running is in fact the code inside alarm[7].
 
7

7bones

Guest
Thx for help.Puting save in alarm after using instance_activate_all solved the problem
 
I

icuurd12b42

Guest
activate/deactivate take one step to apply... so this

instance_activate_all()
with obj_blood_parent {event_user(0)} /////makes obj_blood_parent.save=true

will fail. this is not gm8...
 
Top