Basic Scripting:Override Output
The methods presented here are offered as beginner's tools, in that you can use them simply by writing strings, without any custom code. In fact, any of these methods can accept a string or an array or a function, because they pass through getStringArrayFunction() on their way to the player. For now we're focused on the string methods, but we'll present examples of each type, just to introduce the concepts. You're welcome to use whichever methods make the most sense to you as they are all equally valid.
Override per verb:
override_failure_msg,
override_success_msg
Override per verb subscription:
on_failure, on_first_failure,
on_success, on_first_success,
then_destroy
Override per turn:
prependOutput, appendOutput,
overrideOutput
override_failure_msg, override_success_msg
These two methods broadly override a verb's success or failure messages for
all assets. They are the simplest and bluntest tool of all the available
methods. Using these requires calling the game.patchVerb() method
to edit the verb itself.
In this first example we'll set the verb fly to return a snarky
response on any success or failure. Here's an example of the default output.
String
MyGame.patchVerb({
name: "fly",
override_failure_msg: "Do you see wings? I don't see wings. ",
override_success_msg: "Wheee! ",
}),
And the results:
Array
In the next example, we'll set each override property of fly to
an array. Arrays are recognized automatically by
getStringArrayFunction()
and can be set to return array items randomly or sequentially.
MyGame.patchVerb({
name: "fly",
override_failure_msg: {
randomize: true,
array: [
"No.",
"You find that you can't.",
"You bump your head on the ceiling.",
],
},
override_success_msg: {
randomize: true,
array: [
"Wheee!",
"You fly!",
"Up, up, and away!",
],
},
});
And the results:
Function
In this example, we set each override property of fly to a
function. When a function is found it is automatically called by
getStringArrayFunction(). If the function returns a string, that will override the default output.
(In fact, the function isn't required to return a string; it can be used to
run custom code instead. We'll cover variations on that in a later tutorial.)
MyGame.patchVerb({
name: "fly",
override_failure_msg: function () {
if(MyGame.getPlayer().$is("wearing", "wax wings")){
return `Though you're wearing the wax wings, conditions don't permit it. `;
} else {
return `You might need a flying aid. `;
}
},
override_success_msg: function () {
if(MyGame.getPlayer().$is("wearing", "wax wings")){
return `Be careful not to fly too close to the sun! `;
}
},
});
And the results:
on_failure, on_first_failure, on_success, on_first_success, then_destroy
These methods are features of verb subscriptions. Objects use verb subscriptions to tell verbs how to act on them. Each verb subscription can be uniquely customized. These methods can be used to append text to a verb's output when the verb acts on the object that is subscribed to it.
Here's our basic setup and a default output.
MyGame.createAsset({
class: "Player",
name: "Hero",
)};
MyGame.createAsset({
class: "Edible",
name: "stinky cheese",
)};
on_first_failure
Only called the first time the verb fails to be applied to this asset, in case you want a variation between the first attempt and subsequent attempts.
MyGame.createAsset({
class: "Edible",
name: "stinky cheese",
dov: {
eat: {
on_first_failure: `It's far too strong. You're going to need a good strong stout to pair it with.`,
},
},
)};
on_failure
Called each time the verb fails to be applied to this asset.
MyGame.createAsset({
class: "Edible",
name: "stinky cheese",
dov: {
eat: {
on_failure: `Not without a good strong stout at hand. `,
},
},
)};
on_first_success
Only called the first time the verb is successfully applied to this asset, in case you want a variation between the first use and subsequent uses.
MyGame.createAsset({
class: "Edible",
name: "stinky cheese",
dov: {
eat: {
on_first_success: `Then, you sip the strong stout. The two bold flavors complement each other brilliantly.`,
},
},
)};
on_success
Called each time the verb is successfully applied to this asset.
MyGame.createAsset({
class: "Edible",
name: "stinky cheese",
dov: {
eat: {
on_success: `It goes down well with the strong stout.`,
},
},
)};
then_destroy
If asset.dov.verb.then_destroy is set to any value, the asset
will be destroyed after the verb is applied.
MyGame.createAsset({
class: "Edible",
name: "stinky cheese",
dov: {
eat: {
then_destroy: `You greedily gulp down the entire block of cheese.`,
},
},
)};
Results
In the prior examples we showed one method at a time to help distiguish them, but because they all operate on the same object, we would define them all together.
MyGame.createAsset({
class: "Edible",
name: "stinky cheese",
dov: {
eat: {
on_first_failure: `It's far too strong. You're going to need a good strong stout to pair it with.`,
on_failure: `Not without a good strong stout at hand. `,
on_first_success: `Then, you sip the strong stout. The two bold flavors complement each other brilliantly.`,
on_success: `It goes down well with the strong stout.`,
then_destroy: `You greedily gulp down the entire block of cheese.`,
},
},
)};
Finally, here are all four verb subscription properties in action.
And a last word... the default behavior of these methods is to append text. But, just like the override methods above, they can be configured to append, prepend, override, or run custom code.
prependOutput, appendOutput, overrideOutput
These methods can be used to revise the output for the current turn. They're
independent of any particular objects or verbs and can be called from any code
block during the game loop. The following examples show the methods being
called from
doNestThisToThat and doUnnestThisFromThat, which are
verb reaction hooks that you may
not be familiar with yet. Don't worry! We'll cover those in later tutorials.
We'll focus on the act of riding a bicycle that the player is not yet on (as
opposed to riding a bicycle that the player is on already). Here's our basic
setup and a default output.
MyGame.createAsset({
class: "Player",
name: "Hero",
)};
MyGame.createAsset({
class: "Bicycle",
name: "bicycle",
)};
prependOutput
Prepend a string before the beginning of the turn's default output.
MyGame.createAsset({
class: "Player",
name: "Hero",
doNestThisToThat: {
bicycle: function () {
MyGame.prependOutput("You wobble a bit, climbing on. ");
},
},
)};
appendOutput
Append a string to the end of the turn's default output.
MyGame.createAsset({
class: "Player",
name: "Hero",
doUnnestThisFromThat: {
bicycle: function () {
MyGame.prependOutput("You nearly fall down in the process, but manage to make a clumsy recovery. ");
},
},
)};
overrideOutput
Override's the current turn's default output.
MyGame.createAsset({
class: "Player",
name: "Hero",
doNestThisToThat: {
bicycle: function () {
MyGame.overrideOutput("You climb onto the pristine white banana seat of the classic 1964 Schwinn
Stingray, and dream of the adventurous treks to come. ");
},
},
doUnnestThisFromThat: {
bicycle: function () {
MyGame.overrideOutput("You climb, sadly, wistfully off the 1964 Schwinn Stingray, the classic bike
of your dreams, with a vow to ride again soon. ");
},
},
)};