stitch icon indicating copy to clipboard operation
stitch copied to clipboard

Object "Variable Definitions" are not checked by the Stitch parser

Open softwareantics opened this issue 4 months ago • 4 comments

Here is an object with two variable definitions:

image

However, I am getting errors:

image

softwareantics avatar Feb 09 '24 14:02 softwareantics

Ah yeah, that's currently unsupported in Stitch. We declare all of our instance variables in Create Events, so I've never understood the purpose of putting variable definitions in this way. Can you provide any insight on putting variables in via this menu versus defining them in the Create event?

adam-coster avatar Feb 19 '24 14:02 adam-coster

Closing for now, but this can be re-opened if someone has a use case for creating object variables this way rather than in Create events.

adam-coster avatar Feb 21 '24 00:02 adam-coster

Ah yeah, that's currently unsupported in Stitch. We declare all of our instance variables in Create Events, so I've never understood the purpose of putting variable definitions in this way. Can you provide any insight on putting variables in via this menu versus defining them in the Create event?

This can be important in a situation for UI, as an example:

// Variable definitions
color = c_red;
text = "Hello, World";

Placing a UI element in the room - where I'd like to change the color would involve me updating it's creation code which can be tedious for multiple elements. With variables definitions it's as simple as clicking on the element and modifying the variable definition.

softwareantics avatar Feb 28 '24 08:02 softwareantics

Ah, gotcha. We do all of our object placement programmatically, so I didn't even know this was a thing! I'll re-open since it'd be good to support that, though since we don't use that feature ourselves I'm not sure if/when I'll get it addressed.

While perhaps less than ideal, you can use the following workaround:

  • In the Create event for an object with variables like that,
  • Add a comment containing the Stitch-specific (i.e. unknown to GameMaker + Feather) @instancevar JSDoc to describe your variable.

So in your example, you'd have something like:

// (In the create event)
/// @instancevar {Constant.Color} color
/// @instancevar {String} text

Note for future self, or for anyone who wants to take a crack at this:

Instance variables defined via the GameMaker "Variable Definitions" UI will end up somewhere in the object's .yy file. That will be easy to ingest during load, since we already have a full schema for this content:

https://github.com/bscotch/stitch/blob/929d96406b6ee67f0dfdf359c79fb0f7be89389d/packages/yy/src/types/YyObject.ts#L118

We'd just need a mapping of the numeric type IDs to the corresponding Feather/Stitch type names. They wouldn't get re-parsed on update without some additional work, and aren't meaningfully available to edit via Stitch VSCode, but that'd be a start.

adam-coster avatar Feb 29 '24 20:02 adam-coster