• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code variable_instance_set occasionally doesn't work

T

TylerCamp

Guest
This has been driving me crazy - I'm making a tool for custom datastructures by storing properties and default values, and assigning them to data instances with variable_instance_set.

It's been really temperamental. Sometimes when I run it, it works like a charm. At other times it just seems to ignore variable_instance_set.

I do a lot of extra logic in my system so there's room for error in how I set the variables. HOWEVER - when variable_instance_set breaks, I test with a new blank object and use variable_instance_set with no frills. The variable doesn't get set in that basic object.

The instances in question deactivate themselves in their create event; keeping them active makes no difference.


Currently the attached project runs fine on my desktop, but throws errors on my laptop and my teammate's computer, complaining about unassigned variables (because variable_instance_set didn't do its job)

We've all cleaned our solution and even sent zipped versions of the project to each other to see if there were any code differences.. there were none.



The project in question can be found here:
http://www.teamoverreact.com/ds_custom.zip

What sort of dark magic is happening here?
 
T

TylerCamp

Guest
I'd also be interested in other people's experience running the project - does it crash for some? Does it run for some?
 
A

aft

Guest
i have a similar issue. your project works on windows but not on html module.
 
T

TylerCamp

Guest
I discovered it was an issue with GMS and reported it as a bug; it wasn't working at all on Windows before but now it does. You should probably report it as well.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
I can't test the project as it crashes on startup with a configuration error. You should export it as a YYZ rather than zip the project...

That said... My first feeling on the subject is that the problem is because of the instance deactivation in the create event. You should move the deactivate code to the initialisation script so that the instance is deactivated after all the values have been set. When you create an instance, its create event is run before the rest of the ocde in the script that created is run, so it's been created and then deactivated and then you are trying to access it. Now, deactivating an instance usually requires 1 step to complete, and in that step the instance is in a kind of list-limbo, so I suspect that the issue is with that... So, for example, your ds_custom_create() script becomes:

Code:
//    Run init on the first call
if (!variable_global_exists("custom_ds_obj_pool")) {
    var max_objs = 1000;
    global.custom_ds_max_objs = max_objs; // Increase this as necessary (above ~5000 can hurt perf.)

    global.custom_ds_obj_pool = array_create(max_objs, -1);
    global.custom_ds_obj_pool_vacancy = array_create(max_objs, true);
    global.custom_ds_num_instances = 0;
    global.custom_ds_search_start = 0;
   
    var inst;
    for (var i = 0; i < max_objs; i++) {
        inst = instance_create_depth(0, 0, 0, obj_ds_custom_instance);
        global.custom_ds_obj_pool[i] = inst;
        inst.custom_pool_index = i;
        instance_deactivate_object(inst);
    }
}

var name = argument0;

var new = instance_create_depth(0, 0, 0, obj_ds_custom_type);
new.name = name;
instance_deactivate_object(new);
return new;

Other than that, all I can say is to file a bug and link to the YYZ of the file.
 
T

TylerCamp

Guest
The issue has been fixed for Windows after the bug was reported and confirmed. I haven't tested in HTML5 so I assume that's a separate bug.

That being said, the posted code works completely as expected.

If the behavior of modifying deactivated instances is undefined then I request it be documented somewhere. I wrote it as such since there was no mention in the docs of variable access in deactivated instances. In this case, the bug I documented was that variable_instance_set wasn't working at all. Deactivated instances might work differently across different platforms, and my code now works at least on Windows.

HTML5 is not my target platform. If aft wants it fixed, he should modify the project for a minimal example to repro the bug. I'd upload the YYZ but I can't seem to log in to GMS at the moment.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Okay, cool... I'll see if I can't find out the exact deatils for instance activation/deactivation timings and add something to the manual on the appropriate pages. As for the login issue, yeah, it seems YYG are having issues with their servers... :(
 
A

aft

Guest
cool. glad it works for you.

i have already posted a bug report with my example for the html module.

for people who may have the same issue, i'll post the link here when they add it to the bug tracker. there are some additional bugs with variable_instance_* functions on the html module which i may share after they respond.
 

rwkay

GameMaker Staff
GameMaker Dev.
I fixed quite a few issues with variable_instance_* functions about 2 weeks ago (everything that has been reported at that point) - this will be in the next public update.

This includes several HTML5 fixes.

Most of the issues revolved around accessing built in variables (instance and global) that were not being supported correctly across platforms.

Russell
 
  • Like
Reactions: aft
Top