[S] Assorted Inquiry: Input conversion to lowercase, Typewriter FX sans linebreak, and Millisecond-incremental timers

Cylius_Optimi
12 Jan 2016, 22:02
First off, I'm working on a game (like many others are, of course). I had some experience playing around with the earlier versions of the QDK back in '08-'09, so I've had only limited difficulty figuring out how to make things work.

However, what difficulties I do encounter are quite annoying. I would appreciate some help from those who have up-to-date experience with Quest game creation.


1.) I have noticed that LCase (string) in the online documentation (as well as UCase (string)) is missing from the library-provided functions list in QDK today.

I have what amounts to a keyphrase-searchable journal command that lets the player view acquired information on a variety of topics. However, I noticed this while testing a switch case that included phrases using capital letters: if the player enters inexact case of an existing topic into the 'topic' field, it will return an error, completely foregoing my 'default' case. Having taken to the internet for a solution, I tried using LCase (text) to first convert whatever the player enters into pure lowercase.

An immediate F5 test of the new code dashed my hopes entirely. The game would not load, as there was 'no such function'. Because of this, I would like to know what happened to LCase; will I need to make my own workaround, or is there a new method used to convert a string to lowercase?

In either case, the documentation pages should be updated accordingly.


2.) I want to output subsequent Typewriter entries to the same line, at varying speeds, and with delays between them.

I've noticed while using the Typewriter effect to print text that it follows several rules: It always ignores HTML formatting tags within the text to type, it always prints on a new line, and it never prints text onto the typewritten line, even with Print (no line break). I want to utilize the Typewriter effect to simulate speech, similar to text boxes in games with dialog (e.g. Megaman Battle Network, Golden Sun, or other RPGs), but I would definitely need to be able to bypass those latter two rules to do so.

To accomplish that, I assume I would likely have to customize it myself; especially as I would like to eventually implement brief speech sounds with each character (again, as in Battle Network/Legends, Golden Sun, Undertale, etc). I would definitely appreciate any advice towards this task.


3.) I need a timer, for several reasons, that increments in milliseconds. If not milliseconds, I would at least like one that can use tenth-seconds.

If I can't learn/figure out how to hook onto the typewriter effect to use the end of the printed text as a trigger for the next action, being able to use a timer that isn't either 1 second or 2 seconds long would definitely be the next best jury rig.

I would hazard a guess that someone, somewhere has already written a library or code snippet for either a new timer or a replacement that counts in milliseconds; if anyone knows about one, I'd appreciate it if you could tell me about it.

jaynabonne
12 Jan 2016, 22:12
1) LCase is part of the expression parsing. It's not a function as such. That distinction is probably less than clear, but the bottom line is that you can't do this:

LCase("Some String")

but you can do something like:

x = LCase("Some String")

or

msg(LCase("Some String"))

More on the other two later.

jaynabonne
12 Jan 2016, 22:32
2) The typewriter function is coded in JavaScript, and you can find the implementation in the quest source in playercore.js. Given the way that JavaScript works, you can actually replace those implementations with your own. For example, whenever it adds a text effect, it calls this:

   function addFx(text, font, color, size) {
fxCount++;
var style = "font-family:" + font + ";color:" + color + ";font-size:" + size + "pt";
var html = "<span id=\"fx" + fxCount + "\" style=\"" + style + "\">" + text + " </span><br />";
addText(html);
return $("#fx" + fxCount);
}

As you can probably see, there is the culprit: the <br/> after the span. I'm not sure how skilled you are in JS. If so, I can try to point you to things. Otherwise, given some small time, I might be able to put something together.

As far as notifying the app when done, I've done that myself in similar situations. The key there is the ASLEvent JavaScript function that you can use to call a function in the .aslx file. You can see how to use it here: http://docs.textadventures.co.uk/quest/ ... cript.html

3) I would need to know what you mean by "timer". Do you mean something like the Quest timers, where your script is invoked every so often (and I assume you want tenth second or greater resolution), or do you just want to be able to query the time to millisecond accuracy? If the former, I'd do a lot of testing on any solution, as the web player is quite finicky with timing code. I had problems with my own title screen, in terms of using ASLEvent to trigger endings in some cases. So I'd be sure you really need this before going down that road!

Cylius_Optimi
13 Jan 2016, 00:28
jaynabonne wrote:1) LCase is part of the expression parsing. It's not a function as such. That distinction is probably less than clear, but the bottom line is that you can't do this:

LCase("Some String")

but you can do something like:

x = LCase("Some String")

or

msg(LCase("Some String"))

More on the other two later.


Thanks for the info! I didn't realize that LCase couldn't be called by itself; I preceded the switch with a line to set text_topic to LCase(text_topic) and it worked perfectly.

jaynabonne wrote:2) The typewriter function is coded in JavaScript, and you can find the implementation in the quest source in playercore.js. Given the way that JavaScript works, you can actually replace those implementations with your own. For example, whenever it adds a text effect, it calls this:

   function addFx(text, font, color, size) {
fxCount++;
var style = "font-family:" + font + ";color:" + color + ";font-size:" + size + "pt";
var html = "<span id=\"fx" + fxCount + "\" style=\"" + style + "\">" + text + " </span><br />";
addText(html);
return $("#fx" + fxCount);
}

As you can probably see, there is the culprit: the <br/> after the span. I'm not sure how skilled you are in JS. If so, I can try to point you to things. Otherwise, given some small time, I might be able to put something together.

As far as notifying the app when done, I've done that myself in similar situations. The key there is the ASLEvent JavaScript function that you can use to call a function in the .aslx file. You can see how to use it here: http://docs.textadventures.co.uk/quest/ ... cript.html


I don't have in-depth experience with JS, but I've picked up enough of it that I'm confident I can put something workable together if I study the existing Typewriter effect and consult Google for help.

For posterity's sake, CodeAcademy is a good place to quickly pick up the basics of JavaScript. I spent maybe twenty minutes there years back when I was first learning about coding, and while it wasn't particularly helpful for high-level scripting, it was a good way to introduce basic coding concepts to anyone.

jaynabonne wrote:3) I would need to know what you mean by "timer". Do you mean something like the Quest timers, where your script is invoked every so often (and I assume you want tenth second or greater resolution), or do you just want to be able to query the time to millisecond accuracy? If the former, I'd do a lot of testing on any solution, as the web player is quite finicky with timing code. I had problems with my own title screen, in terms of using ASLEvent to trigger endings in some cases. So I'd be sure you really need this before going down that road!


I actually mean an effect like SetTimeout. Frankly, the only reason I could foresee needing it is as a last-ditch, jury-rigged solution to my 'speech' effect, but the information you've provided here probably will probably make a hack-job like that a moot point.