SOL, Object Scopes, and all that.

3

Features on these Courses

Contributors

Stats

1,924 visits, 2,490 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 29 Aug, 2019.

Scopes

Wake up sheeple, Construct is FOOLING YOU.

Programming doesn't work the way Construct wants you to believe. It actually does some super shady stuff behind the scenes so you feel comfortable and trust it.

if(Enemy.HP = 0) then Enemy.Die() doesn't magically pick every enemy objects that have 0 HP and kills them.

What Construct actually does is understand that what you're actually meaning to do is pick every Enemies, check which ones have a HP value of 0 and execute the code for them only.

That process of choosing which objects to execute stuff on is named "Object scoping", and the thing that holds that information is named the SOL (Selected Objects List).

There are a few things to know about the SOL and how it works:

Each object type has its own SOL. Meaning picking Enemies doesn't affect how your Players are picked.

That includes Families. Picking Family objects doesn't automatically pick linked object types in said family.

By default, every object is in the SOL.

The SOL is passed down to sub events. To reset an object type's SOL, use the system "Pick all" condition

When creating an object, that object's type's SOL gets overwritten to contain only that created object for that event block.

When I say "that event block" I also mean its sub events.

Functions don't keep the SOL from where they were called.

SOL is updated using conditions from TOP TO BOTTOM and will execute the following conditions as long as the SOL isn't empty.

Properly picking your instances will be your #1 tool for reducing code complexity in your Construct Code.

If you're looping over every instance of an object and then making checks, you should probably moving these checks above your for each loop to avoid some instances getting needlessly looped over.

Additional must reads

How Scopes work in Multimedia Fusion, its más o menos the same in Construct: diybandits.com.au/MMF/article_objectscope.html

Some required knowledge concerning containers: construct.net/en/make-games/manuals/construct-3/project-primitives/objects/containers

Picking using System conditions (search for "PICK INSTANCES"): construct.net/en/make-games/manuals/construct-3/system-reference/system-conditions

  • 1 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • Great read, and straight to the point. Reminded me of some things, and the must reads are very useful, thank you for the tutorial!