snowman
snowman copied to clipboard
Class/ES6 Problem with Snowman 2
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.)
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"));