Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

[Solution] Commands don't work for languages that don't use spaces between words.

A topic by judypao29 created Dec 25, 2023 Views: 368 Replies: 9
Viewing posts 1 to 2
(2 edits) (+1)

Hi all,

As I was testing the game in Traditional Chinese, I found that action commands were not coded to accomodate languages that don't have spaces between words (Chinese, Japanese, etc.)

The code requires the input to be 拿  降落傘 (TAKE PARACHUTE), but a typical player would type 拿降落傘 (no space).

To fix this, go to: IFEngine --> js --> Parser.js. Do the following in Parser.js:

1. Change line 75 from  

"(?:\\s+(.+))?" : 

to

"(?:\\s*(.+))?" :

2. Change line 76 from

"\\s+(.+)";

to

"\\s*(.+)";

This will allow the game to process user inputs that don't contain spaces in the text. 

Note: this change won't break the original game (IT, EN). The user will still be able to input "TAKE PARACHUTE" however, this change would also allow "TAKEPARACHUTE" as a valid input. Not sure if this is a behavior that the original devs want to allow. 

(1 edit)

Additionally, since typing works differently in Chinese (and several other languages), the user must type their inputs in the mobile text box. 

For example, the word TAKE (拿) is typed using the keyboard letters ㄋㄚˊ  (in zhuyin) or na6  (in pinyin). 

If the user tries to type in the main textbox, the inputs become literal phonetics rather than words. 

I'm currently reading through the code to see if I can put in a fix, will update here if I get it working. If any devs see this, feel free to chime in, will be happy to help get this working for languages that don't use the english alphabet!


(2 edits)

I could not get the normal input area to work as the keyboard will send the raw English characters directly even when the Chinese keyboard is enabled. However, the keyboard can detect the mobile input as an input area, which is why the intermediate spelling (e.g. na6) can be entered in order to select the correct Chinese character.

To ensure that the mobile input is used, I made the following changes in IFEngine --> js --> CRT.js:

1. Change line 223

From

// this.mobileInput.focus();

to

this.mobileInput.focus();

This ensures that the user enters into the mobile input by default.

2. Enable backspace in mobile input

Line 266 is currently

if(inputTxt.length > 0){

Replace it with

if (this.mobileInput.value != "") {
    this.mobileInput.value = this.mobileInput.value.substring(0, this.mobileInput.value.length - 1);
}
else if (inputTxt.length > 0){

Hello,


Yes, the bottom bar was enabled to allow chinese/Japanese/Korean input. It was born for the mobile and adjusted for this Jam (if you see the original italian version here:  https://www.avventuranelcastello-js.it/play/ it only appears in mobile devices)

BTW great job in updating the parser for the "no space" languages!

Federico :)

Found a new issue regarding spaces in the parser :)

As an example, in English the insertInto pattern is `(put|insert|stick) (.+) (?:in) (.+)`. If given an input like "insert bone into hole", Parser correctly generates an action object even though the pattern matches the input exactly. This is because the initial match is skipped:

if(
    sorgente != this.commands &&
    override != this.override.commands &&
    input.indexOf(" ") == -1 &&
    (obj.singolo === undefined || obj.singolo == false)
){
    let matches = input.match(new RegExp("^"+pattern+"$", 'i'));
    if( matches != null)
        return input;
}

The input contains spaces, so the above logic is skipped due to `input.indexOf(" ") != -1`. Otherwise, there would be a match and the raw input would be returned directly.

It appears the presence of the space is used to indicate whether this is an action and/or potentially has subjects. Unfortunately, since there are no spaces in Chinese, any inputs that match the pattern enter the above logic and return a string, not an action object. As an example, we would enter the Chinese equivalent of "insertboneintohole" and Parser.parse will return the string instead of the action.

How would you recommend adjusting the logic to handle this? I'm not sure if it is safe to remove the `input.IndexOf(" ") == -1` condition.

My fix right now is to remove the initial check (that was copied in the previous post). This avoids looking for spaces to detect the presence of a subject when `sorgente` is the set of verbs.

Then, right before the following return statement

// Rirotno un oggetto contenente l'azione e i soggetti
return {
    verb: chiave,
    actionObject: obj,
    command: sorgente == this.commands, //patternEsatto == true,
    subjects: subjects
}

I added the subject check:

if(
    sorgente != this.commands &&
    override != this.override.commands &&
    (obj.singolo === undefined || obj.singolo == false)
) {
    if( subjects.length == 0)
        return input;
}
// Rirotno un oggetto contenente l'azione e i soggetti

Ok I think your solution can work... just test it :)

Thanks for validating!

I did a play-through with no issues, this solution should be good to go for any other languages that have the same problem 😊

perfect :D

(2 edits)

Hi there,

Indeed, I can confirm that the main prompt is limited to the roman alphabet.
The input box underneath (long empty rectangle in your screenshot) was added specifically for inputting Asian characters.
I will let Federico check and reply about there rest 😄

Merry Christmas!