> what is es5 and es6?
The modern JavaScript language is an implementation of the ECMAScript specification, and that specification has multiple versions, two of which are known as ES5 and ES6.
The JavaScript runtimes found in web-browsers are built to support specific versions of ECMAScript (which ones they support are up to the developers to deside), although they may also include selected features from later version of the specification. Versions of modern web-browser released since 2010 (ish) generally support all the features of the ES5 specification.
> ...am i supposed to keep all these variables and classes in...
Variables and object definitions can be kept in a number of locations, depending on how you like to code and what you're planing to do with them.
Based on the code in your example it appears as if the weapon class definitions are Static, and by that I mean that the properties of a specific weapon don't change once it has been defined. If this is true then I would suggest defining them on the special 'global-like' setup object that the story format supplies for this purpose.
There are a number of ways you can define your custom object types:
A. Using a Generic Object from a TwineScript passage.
/* Using the <<silently>> macro to suppress the visual output of the following. */
<<silently>>
/* Define the contain to store all the weapon definitions in. */
<<set setup.weapons to {}>>
/* Define the actual weapons. */
<<set setup.weapons["Beginner's Blade"] to {
name : "Beginner's Blade",
cost : 50,
weight : 'light',
effects : 'none',
maxdamage : 6,
mindamage : 0,
description : 'The beginning blade of many a traveler.',
attributes : ['slashing'],
sellprice : 25
}>>
<<set setup.weapons["Rusted Blade"] to {
name : "Rusted Blade",
cost : 5,
weight : 'light',
effects : '-2 to attack',
maxdamage : 4,
mindamage : 0,
description : 'A rusted blade dulled by disuses but better for protection than luck.',
attributes : ['dull', 'slashing'],
sellprice : 3
}>>
/* Tracking the player's current weapon. */
<<set $wielding to "Rusted Blade">>
<</silently>>\
/* Displaying the name and description of the currently wielded weapon. */
\The player is wielding a $wielding, which looks like <<= setup.weapons[$wielding].description>>
B. Using a Generic Object defined in JavaScript and referenced in a TwineScript passage.
The following code is added to your project's Story Javascript area, it defines the weapons using Generic Objects.
/* Using a Generic Object. */
setup.weapons = {};
setup.weapons["Beginner's Blade"] = {
name : "Beginner's Blade",
cost : 50,
weight : 'light',
effects : 'none',
maxdamage : 6,
mindamage : 0,
description : 'The beginning blade of many a traveler.',
attributes : ['slashing'],
sellprice : 25
};
setup.weapons["Rusted Blade"] = {
name : "Rusted Blade",
cost : 5,
weight : 'light',
effects : '-2 to attack',
maxdamage : 4,
mindamage : 0,
description : 'A rusted blade dulled by disuses but better for protection than luck.',
attributes : ['dull', 'slashing'],
sellprice : 3
};
The following code is added to a Standard Passage, it makes use of the pre-defined weapons.
/* Tracking the player's current weapon. */
<<set $wielding to "Rusted Blade">>\
/* Displaying the name and description of the currently wielded weapon. */
\The player is wielding a $wielding, which looks like <<= setup.weapons[$wielding].description>>
C. Using a Constructor Function defined and used in JavaScript, and referenced in a TwineScript passage.
The following code is added to your project's Story Javascript area, it defines the MeleeWeapon constructor function, and then uses that function to create some weapons.
setup.MeleeWeapon = function (
name, cost, weight, effects, maxDamage, minDamage, description,
attributes, sellPrice) {
this.name = name;
this.cost = cost;
this.weight = weight;
this.effects = effects;
this.maxDamage = maxDamage;
this.minDamage = minDamage;
this.description = description;
this.attributes = minDamage;
this.sellPrice = sellPrice;
};
setup.weapons = {};
setup.weapons["Beginner's Blade"] = new setup.MeleeWeapon(
"Beginner's Blade", 50, 'light', 'none', 6, 0,
'The beginning blade of many a traveler.', ['slashing'], 25
);
setup.weapons["Rusted Blade"] = new setup.MeleeWeapon(
"Rusted Blade", 5, 'light', '-2 to attack', 4, 0,
'A rusted blade dulled by disuses but better for protection than luck.', ['dull', 'slashing'], 3
);
The following code is added to a Standard Passage, it makes use of the pre-defined weapons.
/* Tracking the player's current weapon. */
<<set $wielding to "Rusted Blade">>\
/* Displaying the name and description of the currently wielded weapon. */
\The player is wielding a $wielding, which looks like <<= setup.weapons[$wielding].description>>
D. Using a Constructor Function defined in JavaScript within a TwineScript passage.
The MeleeWeapon constructor function is that same as the previous JavaScript example, the only difference is that the defining of the different weapons if moved to a Standard Passage like so.
<<silently>>
<<set setup.weapons to {}>>
<<set setup.weapons["Beginner's Blade"] = new setup.MeleeWeapon("Beginner's Blade", 50, 'light', 'none', 6, 0,
'The beginning blade of many a traveler.', ['slashing'], 25
)>>
<<set setup.weapons["Rusted Blade"] = new setup.MeleeWeapon("Rusted Blade", 5, 'light', '-2 to attack', 4, 0,
'A rusted blade dulled by disuses but better for protection than luck.', ['dull', 'slashing'], 3
)>>
/* Tracking the player's current weapon. */
<<set $wielding to "Rusted Blade">>\
<</silently>>\
/* Displaying the name and description of the currently wielded weapon. */
\The player is wielding a $wielding, which looks like <<= setup.weapons[$wielding].description>>