Commit 390c2e48 authored by Leon Arnott's avatar Leon Arnott
Browse files

Fixed (random:) producing an error when given one non-zero whole number instead of two.

Additionally, backported several small fixes from 2.0.0, for a 1.2.4 release.
parent 332aca4392b2
......@@ -2,7 +2,16 @@
Rough documentation is at http://twine2.neocities.org/
###1.2.3 changes (unreleased):
###1.2.4 changes:
* `(random:)` now no longer incorrectly errors when given a single whole number instead of two.
* `(alert:)`, `(open-url:)`, `(reload:)` and `(goto-url:)` now return empty strings rather than the non-Harlowe value `undefined` (or, for `(open-url:)` a Javascript Window object). This differs slightly from 2.0, which returns more useful command values.
* Additionally, backported the following fixes from 2.0.0:
* Fixed a bug where comparing a value with an error (such as `2 is (3 + 'X')`) would suppress the error.
* Fixed a bug where subtracting non-subtractable values (such as booleans) wouldn't produce an error, instead implicitly converting the values to numbers, and potentially producing the Javascript value `NaN`.
* Fixed the bug where `(current-time:)` wouldn't pad the minutes value with a leading 0 when necessary, and '12' was printed as '0'.
###1.2.3 changes:
####Bugfixes
......
window.storyFormat({"name":"Harlowe","version":"1.2.3","author":"Leon Arnott","description":"The default story format for Twine 2. See its <a href='http://twine2.neocities.org/'>documentation</a>.","image":"icon.svg","url":"http://twinery.org/","license":"Zlib","proofing":false,"source":"","setup":""});
window.storyFormat({"name":"Harlowe","version":"1.2.4","author":"Leon Arnott","description":"The default story format for Twine 2. See its <a href='http://twine2.neocities.org/'>documentation</a>.","image":"icon.svg","url":"http://twinery.org/","license":"Zlib","proofing":false,"source":"","setup":""});
......@@ -242,9 +242,11 @@ define(['macros', 'utils/operationutils', 'internaltypes/twineerror'],
// The current time in 12-hour hours:minutes format.
currenttime: [() => {
const d = new Date(),
am = d.getHours() < 12;
am = d.getHours() < 12,
hr = ((d.getHours() % 12) || 12),
mins = (d.getMinutes() < 10 ? "0" : "") + d.getMinutes();
return d.getHours() % 12 + ":" + d.getMinutes() + " " + (am ? "A" : "P") + "M";
return hr + ":" + mins + " " + (am ? "A" : "P") + "M";
},
null],
......@@ -283,7 +285,7 @@ define(['macros', 'utils/operationutils', 'internaltypes/twineerror'],
/*
This function returns a random integer from a to b inclusive.
*/
random: [(a, b) => {
random: [(a, b = 0) => {
/*
First, throw an error if either of the numbers is not a whole number.
*/
......@@ -310,15 +312,15 @@ define(['macros', 'utils/operationutils', 'internaltypes/twineerror'],
*/
// Keep "undefined" from being the default text.
alert: [(text) => window.alert(text || ""),
alert: [(text) => window.alert(text || "") || "",
String],
prompt: [(text, value) => window.prompt(text || "", value || "") || "",
String, String],
confirm: [(text) => window.confirm(text || ""),
String],
openURL: [window.open, String],
reload: [window.location.reload.bind(window.location), null],
gotoURL: [window.location.assign.bind(window.location), String],
openURL: [url => window.open(url) && "", String],
reload: [() => window.location.reload() || "", null],
gotoURL: [() => window.location.assign() || "", String],
pageURL: [() => window.location.href, null],
/*
......
......@@ -119,6 +119,10 @@ define([
*/
function comparisonOp(fn) {
return (left, right) => {
let error;
if ((error = TwineError.containsError(left, right))) {
return error;
}
It = left;
return fn(left, right);
};
......@@ -260,7 +264,13 @@ define([
*/
return l.split(r).join('');
}
return l - r;
/*
Finally, if it's a number, subtract it.
*/
if (typeof l === "number") {
return l - r;
}
return TwineError.create("operation", "I can't use - on " + objectName(l) + ".");
}),
"*": onlyPrimitives("number", doNotCoerce((l, r) => l * r), "multiply"),
"/": onlyPrimitives("number", doNotCoerce((l, r) => {
......
{
"name": "twine-harlowe",
"version": "1.2.3",
"version": "1.2.4",
"author": "Leon Arnott",
"description": "The default runtime for Twine 2 stories",
"license": "Zlib",
......
......@@ -145,7 +145,7 @@ describe("twinescript operators", function () {
it("compares datamaps by value", function (){
expectMarkupToPrint("(print: (datamap:) is (datamap:))","true");
expectMarkupToPrint("(print: (datamap:'a',2,'b',4) is (datamap:'b',4,'a',2))","true");
expectMarkupToPrint("(print: (datamap:) is (datamap:1))","false");
expectMarkupToPrint("(print: (datamap:) is (datamap:1,2))","false");
expectMarkupToPrint("(print: (datamap:'a',2,'b',4) is (datamap:'b',4,'a',3))","false");
});
it("compares datasets by value", function (){
......@@ -183,7 +183,7 @@ describe("twinescript operators", function () {
it("compares datamaps by value", function (){
expectMarkupToPrint("(print: (datamap:) is not (datamap:))","false");
expectMarkupToPrint("(print: (datamap:'a',2,'b',4) is not (datamap:'b',4,'a',2))","false");
expectMarkupToPrint("(print: (datamap:) is not (datamap:1))","true");
expectMarkupToPrint("(print: (datamap:) is not (datamap:1,2))","true");
expectMarkupToPrint("(print: (datamap:'a',2,'b',4) is not (datamap:'b',4,'a',3))","true");
});
it("compares datasets by value", function (){
......
......@@ -94,7 +94,7 @@ describe("data structure macros", function () {
it("shuffles the positions of the elements in the returned array", function() {
expectMarkupToPrint("(print: (range:1,99) is (range:1,99))","true");
for(var i = 0; i < 10; i += 1) {
expectMarkupToPrint("(print: (shuffled:(range:1,99)) is not (shuffled:(range:1,99)))", "true");
expectMarkupToPrint("(print: (shuffled:...(range:1,99)) is not (shuffled:...(range:1,99)))", "true");
}
});
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment