snowman icon indicating copy to clipboard operation
snowman copied to clipboard

Class/ES6 Problem with Snowman 2

Open videlais opened this issue 2 years ago • 1 comments

As reported on YouTube

"Is there any way to use ES6's classes in Snowman 2 so that I can have global custom data types? Would something like this work?"

s.object = class {
  constructor(x, y) {
    ...
  }
  ...
}

This seems to be tied to the #526 and #516 problem of how template code is handled internally. (This has been fixed in Snowman 3, but not back-ported to Snowman 2.)

videlais avatar Aug 17 '23 05:08 videlais

The following worked for me, though I admittedly use a third party app (Tweezel) instead of the official Twine app so I'm not sure if it'll run on the official app.

s.Crop = class {
  constructor(type, maxAge, cost, price, season) {
    this.type = type;
    this.maxAge = maxAge;
    this.cost = cost;
    this.price = price;
    this.season = season;
  }
}

s.crops = [];
s.crops.push(new s.Crop("Potato", 6, 50, 100, "Spring"));
s.crops.push(new s.Crop("Cauliflower", 12, 80, 175, "Spring"));

byronpendason avatar Aug 17 '23 10:08 byronpendason