theRAPTLab / gsgo

GEM-STEP Foundation repo migrated from GitLab June 2023
1 stars 1 forks source link

Compile global before instances so global properties are available - [merged] #729

Closed benloh closed 1 year ago

benloh commented 2 years ago

Merges dev-bl/global-precompile -> dev-next

In the original implementation of global in sim-agents, we compiled global first, then compiled instances. But during QA with older project files, the instance ids from older project specs were interfering with the global id, resulting in global agents being reassigned to other agents. So we had reversed the order, compiling instances to establish the base ids, then compiling global so it uses a new unique id.

The problem of course, is this means global properties are not available to instances immediately. This was not an obvious error if the instance scripts only referenced global during # PROGRAM UPDATE. But references in # PROGRAM INIT would cause errors because global is not yet defined during INIT.

This fixes the problem by compiling global first, then compiling instances. In addition, we add a check to throw an error if we encounter an older project file that has a conflicting id. If the project does not appear to load, check the console for the following error:

Instance id already in use by Global! Please review your instance ids!!!

The error should list the problem instance spec.

In the current build, the global id is usually 154. (The id is consistently 154 because of the other sm-objects that are created before global -- note that this may change in the future).

TO TEST

Because this changes the compile order, we strongly recommend opening and running all current scripts to make sure there no errors.

You can trigger an error by setting the id of any instance defined in a project to the number 154 (note, not string "154" -- use a text editor to edit the instances array at the end of a project file).

benloh commented 2 years ago

requested review from @jdanish

benloh commented 2 years ago

added 1 commit

Compare with previous version

benloh commented 2 years ago

mentioned in commit 59320bdc2e9ac55de4ab7d9dc7e02aa7ec508e41