tmedwards / sugarcube-2

SugarCube is a free (gratis and libre) story format for Twine/Twee.
https://www.motoslave.net/sugarcube/2/
BSD 2-Clause "Simplified" License
177 stars 41 forks source link

Enhance <<unset>> to handle object properties #223

Closed tmedwards closed 2 months ago

tmedwards commented 1 year ago

What it says on the tin.

Users attempting to use <<unset>> to delete properties from objects stored in story and temporary variables is a common issue. The two obvious solutions are:

  1. Add a warning to its documentation entry, that no one will bother to read.
  2. Enhance it to be able to handle deleting properties from objects.

Option 2 is the clear choice here.

Example documentation

<<unset variableList>>

Unsets story $variables, temporary _variables, and properties of objects stored within either.

History:

Arguments:

Examples:

Basic usage, unsetting story and temporary variables.

<<unset $rumors>>
<<unset _npc>>

<<unset $rumors, _npc, _choices, $job>>

Unsetting object properties.

<<unset _choices.b>>
<<unset $towns['port ulster'].rumors>>

<<unset _choices.b, $towns['port ulster'].rumors, $pc.notes, _park.rides['wheel of death']>>
greyelf commented 1 year ago

@tmedwards And if the end-user did <<unset $towns>> when $towns contained an Object with properties that would cause the $towns variable itself to be unset?

tmedwards commented 1 year ago

It will do exactly what it does now, completely remove the story variable regardless of its value.

The only difference the change to <<unset>> will make is when doing something like <<unset $towns.adelaide>>.