Line-of-Sight: Deleting object within LOS, dynamic variables.

1

Stats

555 visits, 646 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.

Construct 2 (c2) version of the Line of Sight behavior (r275)

When a chosen object is within line of sight (LOS) it becomes selected, even for multiple instances. When a chosen object is not within line of sight it is not selected. This is the basic overview of the Line-of-Sight behavior.

What happens if an object gets deleted within LOS? Common sense dictates that the object is no longer within LOS and will not be apart of the selected objects.

For most games this is fine and does not matter... However if you have an event that looks like this:

In other words:
'guy' have LOS to 'guy_fam' | add data to 'los_dict'
'guy' not have LOS to 'guy_fam' | remove selected data from 'los_dict'

It is important to note that each 'guy' is in a container with a dictionary, in this case 'los_dict'. Additionally 'guy' is in a family called 'guy_fam' to help deal with picking.

When a 'guy' within LOS gets deleted the data relevant to 'guy' does not update under the 'not have LOS' condition. This raises a question, is the deleted 'guy' that was within LOS still a selected object? I don't know. It is possible that LOS cannot deal with an object that does not exist and an object that does not exist cannot fall under the 'not have LOS' condition. Meaning a deleted object cannot fall under the 'not have LOS' condition (because it does not exist and cannot do anything). Regardless, what is known, is that data that is no longer useful needs to be removed.

Here is a solution for this example:

In other words:
When 'guy_fam' is destroyed | add identifier to 'guy_removal' dictionary
In other words:
For each 'guy_removal' key
Pick all 'los_dict' with guaranteed leftover unique data | delete selected data from los_dict (not shown by accident)

This solution will delete the data that is no longer relevant, including the data that isn't covered under the 'not have LOS' condition which did not need to be deleted when objects left LOS. It is enough for this project's propose.

This information appears to be obvious but when one encounters this problem for the first time it is baffling. At first glance one could think Line-of-Sight still thinks the deleted object is still selected and is adding it's data to the dictionary. Thankfully this does not appear to be the case.

Please leave a like, comment, add feedback if this is wrong. Thank you for reading and happy game making!

  • 1 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • In the last image, guy_removal should delete current key as to not cycle through redundant keys.