Stacksmith icon indicating copy to clipboard operation
Stacksmith copied to clipboard

Shared user properties

Open uliwitness opened this issue 3 years ago • 1 comments

A lot of shared information was traditionally kept in globals in HyperTalk. In modern languages, there are many smaller scopes that you can use to avoid namespace collisions between different modules. We already have user properties as a storage that is namespaced to that instance. (a property "foo" on cd btn 1 can be completely different than one of the same name on cd btn 2)

It seems like it could be a good first step to add something like that to user properties. To provide some sort of "shared" user property that can be addressed just like any other user property, but whose value is shared by multiple objects.

Can we find a good syntax for that? Or is it enough to just tell scripters to create an invisible object to hold all those properties and access them from another?

Maybe something like

create cd btn "sharedStorage"
define property "shared1" of cd btn "sharedStorage"

create cd btn "storageAccessor1"
set sharedPropertyContainer of cd btn "storageAccessor1" to cd btn "sharedStorage"
set shared1 of cd btn "storageAccessor1" to 42 -- actually changes shared1 of cd btn "sharedStorage"

?

One major advantage of this would be the brevity of saying my shared1 inside "storageAccessor1"'s script instead of having to write shared1 of cd btn "sharedStorage". Of course it could also be surprising if there was a "storageAccessor2" whose shared1 property would suddenly also change.

uliwitness avatar Jun 29 '21 07:06 uliwitness

Bonus thought: Could this be made a general mechanism, where not just user properties, but the entire script of the sharedStorage is inherited? Kind of a blueprint/class style deal? Or would that be mixing apples and oranges? Given the script would often also need to access non-shared properties, how would you conveniently declare those if they aren't inherited? Why would they be shared and not copied/inherited?

uliwitness avatar Jun 29 '21 07:06 uliwitness