Here's a suggestion to improve the usability of executing JavaScript commands.
Instead of building a command by concatenating strings/arrays with BuildCommand:
VorpleExecuteJavaScriptCommand(BuildCommand("alert('Score: ", score, "')"));
we would open the stream of the JS eval file and print the command directly into it.
VorpleJavaScriptCommand(); ! Opens the file stream.
print "alert('Score: ", score, "')";
VorpleSendJavaScriptCommand(); ! Closes the file stream and sends the command to Vorple.
There'd still be a way to execute a single string, by giving an argument to VorpleJavaScriptCommand (or by using another function):
VorpleJavaScriptCommand("alert('Hello World')"); ! Executes a single string.
Pros:
- We are not restricted by the 7-argument limit of
BuildCommand.
- We can use printing functions, such as
print (char) or print (address).
- We can write arbitrary code after opening the stream, so it's possible to use conditions or loops, like in I7 texts. That means it's easier to build complex JavaScript commands.
- There's no need to handle edge cases like in
VorpleTooltipElementDuration (where we have to open manually the stream because there are two IntToString working on the same array), since it becomes the standard way to directly print into the stream.
- There's no more the ugly
BuildCommand.
- I think we wouldn't need the equally ugly
hugehugestr array anymore since we print directly into the file stream, resulting into a smaller and faster story file.
- It's in my opinion more idiomatic in Inform 6 to work on streams instead of working on strings/arrays.
Cons:
- It takes three lines to execute a simple command like above, instead of only one. This should be solvable by making
VorpleJavaScriptCommand (or another routine) take arguments and making it print them into the stream: VorpleJavaScriptCommand("alert('Score: ", score, "')").
- It's a breaking change, except if we keep the old functions of course. (But if we keep them, the pro of having a smaller and faster story file doesn't apply anymore.)
- It will lead to strange bugs if the author forgets to close the stream with
VorpleSendJavaScriptCommand. (But that shouldn't happen often since it's easy to notice.)
- Authors will have to be careful to handle Unicode in strings and escaping. (But that's easily done with
print (VorpleEscape) uni-string.
- We should make sure that everything plays well with other functions that open streams (e.g.
print (A) obj opens a memory stream to determine whether the object starts with a vowel).
Here's a suggestion to improve the usability of executing JavaScript commands.
Instead of building a command by concatenating strings/arrays with
BuildCommand:we would open the stream of the JS eval file and print the command directly into it.
There'd still be a way to execute a single string, by giving an argument to
VorpleJavaScriptCommand(or by using another function):Pros:
BuildCommand.print (char)orprint (address).VorpleTooltipElementDuration(where we have to open manually the stream because there are twoIntToStringworking on the same array), since it becomes the standard way to directly print into the stream.BuildCommand.hugehugestrarray anymore since we print directly into the file stream, resulting into a smaller and faster story file.Cons:
VorpleJavaScriptCommand(or another routine) take arguments and making it print them into the stream:VorpleJavaScriptCommand("alert('Score: ", score, "')").VorpleSendJavaScriptCommand. (But that shouldn't happen often since it's easy to notice.)print (VorpleEscape) uni-string.print (A) objopens a memory stream to determine whether the object starts with a vowel).