How do I create an in-game language parser?

Get help using Construct 2

Post » Mon Feb 16, 2015 8:29 pm

I'd like to create something where certain text is changed based on a language parser system. For those of you that have played world of warcraft, that's exactly what I'm trying to create (when opposing factions try to speak to eachother, a 'lol' may come out as 'bur' for someone not on the same faction)

I don't think anybody's cracked the code exactly for how Blizzard actually does it, but from what I've been able to gather is that the word that comes out depends on what vowels are in the word and the arrangement of the vowels, as well as how many letters the word contains.

And there's a predetermined list of all possible translations to come out based on the number of letters of a word, for example:
two letter words: An, Ko, Lo, Lu, Me, Ne, Re, Ru, Se, Ti, Va, Ve
three letter words: Ash, Bor, Bur, Far, Gol, Hir, Lon, Mod, Nud, Ras, Ver, Vil, Vos

etc.

You can see the full list here http://www.wowwiki.com/Common_%28language%29

Anyways, I believe I can figure it out as long as I know if it's possible in construct 2 to do any of the following based on the text of a text object: compare letters in each word, compare the vowels of each word, compare the letter count of each word, and possibly compare the placement of vowels in a word, If any of that is possible, then I may be able to figure it out. However I have no idea which expressions correlate to this.

I don't think the idea itself is very complicated. The steps to my idea when it translates a word would be:

1. Determine how many letters are in the word
2. Determine the placement of vowels in the word (so if an "a" is the first letter, or the second, or the third, etc)
3. Determine how many vowels there are
4. Translate the word

So, 'lol' would translate different than what 'all' would be because the placement of vowels is different. See what i'm saying? :)

Thanks for reading, I hope you'll be able to help out!
B
11
S
2
Posts: 91
Reputation: 1,017

Post » Mon Feb 16, 2015 9:23 pm

Yes this is possible? Here is an example for the functions you could use!

If someone could explain why I had to -1 /2 for the vowel count that would be great :P It doesn't bother me too much since I have no need for this; which is probably why I didn't look into it myself.
You do not have the required permissions to view the files attached to this post.
Nothing goes unanswered!
B
22
S
5
G
1
Posts: 430
Reputation: 3,388

Post » Mon Feb 16, 2015 9:50 pm

briggybros wrote:Yes this is possible? Here is an example for the functions you could use!

If someone could explain why I had to -1 /2 for the vowel count that would be great :P It doesn't bother me too much since I have no need for this; which is probably why I didn't look into it myself.


hey man, hope you don't mind I tweaked some stuff in your capx. Realy minor stuff. The '-1' is necessary because you had a ',' at the end of 'vowelPositions' so tokencount counts another token (I was going to remove the last ',' just to remove the -1 but it's not worth it).

The '/ 2' was necessary because you were filling the array twice. I just added a 'set VowelPositions to ""' at the start of getVowelPositions and it's fine. Also something minor but cool, you can use 'Add to' for text as well, so I changed 'System | Set VowelPositions to VowelPositions & ..." to 'System | Add ... to VowelPositions'

BTW you don't need tokenat() just to go through a piece of text character by character, you can just use mid(). Much the same thing in the end though.

edit: you could also reduce all the ORs down to
regex.png
You do not have the required permissions to view the files attached to this post.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Mon Feb 16, 2015 10:28 pm

This is amazing. Would this be able to translate each word within entire sentences too?
B
11
S
2
Posts: 91
Reputation: 1,017

Post » Mon Feb 16, 2015 10:37 pm

Basilboy wrote:This is amazing. Would this be able to translate each word within entire sentences too?


That would be up to you :) With C2 you can manipulate text any way you like, it's all up to your ability to use it.

I don't think the idea itself is very complicated. The steps to my idea when it translates a word would be:

1. Determine how many letters are in the word
2. Determine the placement of vowels in the word (so if an "a" is the first letter, or the second, or the third, etc)
3. Determine how many vowels there are
4. Translate the word


1-3 are easy and you've seen how to. 4 is up to you because the meaning of 'translate' is what you need it to be.

Just one tip, you could reduce the amount of code significantly if you learn regular expressіons (regex). Look it up in the C2 manual (where you won't learn anything unfortunately) or better, Google 'javascript regex'. My usage of it above is very basic. You can do a lot more sophisticated things with it.

So learn the basic text manipulatіon stuff (left, mid, right, tokenat, etc) and then after that Regex if you feel you want/need to.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Tue Feb 17, 2015 2:13 am

codah wrote:
Basilboy wrote:This is amazing. Would this be able to translate each word within entire sentences too?


That would be up to you :) With C2 you can manipulate text any way you like, it's all up to your ability to use it.

I don't think the idea itself is very complicated. The steps to my idea when it translates a word would be:

1. Determine how many letters are in the word
2. Determine the placement of vowels in the word (so if an "a" is the first letter, or the second, or the third, etc)
3. Determine how many vowels there are
4. Translate the word


1-3 are easy and you've seen how to. 4 is up to you because the meaning of 'translate' is what you need it to be.

Just one tip, you could reduce the amount of code significantly if you learn regular expressіons (regex). Look it up in the C2 manual (where you won't learn anything unfortunately) or better, Google 'javascript regex'. My usage of it above is very basic. You can do a lot more sophisticated things with it.

So learn the basic text manipulatіon stuff (left, mid, right, tokenat, etc) and then after that Regex if you feel you want/need to.


That would take too long; It's all too complicated for me to understand, it took me an entire month to understand arrays and arrays are relatively simple. I'm not too sure how to make this system work with entire sentences.
B
11
S
2
Posts: 91
Reputation: 1,017

Post » Tue Feb 17, 2015 4:02 am

I would second the suggestion that you look into regular expressions. They really are made for exactly what you seem to be trying to do here. Using regexs, you can do more versatile translations, do them more efficiently. For example, I might try something like
Code: Select all
var input; // this is the text you are going to translate
var in; //a temporary array to hold words
var t; //temp
var output = "";
in = in.split(" ");
for (var i in in) {
  if (null != (t = in[i].match(/([~aeiou])([aeiou])([~aeiou])([a-z]*)/i))){
    output += " " + t[4] + t[2] + t[3] + t[3] + t[1]
  }
}


Pardon any mistakes. I am new to javascript, and i have not tested this at all. It's just to give you a general idea of what you might do.

What this does is split an input sentance into words based on spaces. Then it tries to match each word against a regular expression, which is the funky bit after in[i].match(). The regular expression looks first for a nonvowel, then a vowel, then another nonvowel, then it considers the word matched and includes any letters that come after that. the regex stores the things it finds in the array t. For example, if you fed it the word "language", it would first match the whole things and store it in t[0] = "language". The subsequent parts of the array contain the groups in the regex, so t = ("language","l","a","n","guage"). The line that starts with output += will add a space, which was removed in the split, then stitch the word back together from the array t in a suitable mangled fashion: guageannl. similarly, you could feed it "lol" and you would get "olll", or give it "similar" and get "ilarimms". You can also make it do letter substitutions and other crazy shenanigans. It becomes a roll your own, extra complicated form of pig latin!

Was this at all what you were looking for?
B
14
S
5
G
1
Posts: 189
Reputation: 1,536

Post » Tue Feb 17, 2015 7:49 pm

bladedpenguin wrote:I would second the suggestion that you look into regular expressions. They really are made for exactly what you seem to be trying to do here. Using regexs, you can do more versatile translations, do them more efficiently. For example, I might try something like
Code: Select all
var input; // this is the text you are going to translate
var in; //a temporary array to hold words
var t; //temp
var output = "";
in = in.split(" ");
for (var i in in) {
  if (null != (t = in[i].match(/([~aeiou])([aeiou])([~aeiou])([a-z]*)/i))){
    output += " " + t[4] + t[2] + t[3] + t[3] + t[1]
  }
}


Pardon any mistakes. I am new to javascript, and i have not tested this at all. It's just to give you a general idea of what you might do.

What this does is split an input sentance into words based on spaces. Then it tries to match each word against a regular expression, which is the funky bit after in[i].match(). The regular expression looks first for a nonvowel, then a vowel, then another nonvowel, then it considers the word matched and includes any letters that come after that. the regex stores the things it finds in the array t. For example, if you fed it the word "language", it would first match the whole things and store it in t[0] = "language". The subsequent parts of the array contain the groups in the regex, so t = ("language","l","a","n","guage"). The line that starts with output += will add a space, which was removed in the split, then stitch the word back together from the array t in a suitable mangled fashion: guageannl. similarly, you could feed it "lol" and you would get "olll", or give it "similar" and get "ilarimms". You can also make it do letter substitutions and other crazy shenanigans. It becomes a roll your own, extra complicated form of pig latin!

Was this at all what you were looking for?


:|
You guys seem to be going into intense detail about the code and programming behind it all, I just want to know how this can be used for entire sentences and not only words.
B
11
S
2
Posts: 91
Reputation: 1,017

Post » Tue Feb 17, 2015 8:58 pm

There's no way around it, you're gonna have to learn some stuff. At a minimum, C2 has the same basic text manipulation functions as other languages. Read up on https://www.scirra.com/manual/126/system-expressions , under 'Text'. These will be more than capable of doing what you need.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Tue Feb 17, 2015 9:10 pm

I wonder if there is a regex plugin?

In any case, look at my code where I make in = input.split(" "). (really, in is not a valid identifier because it is a reserved word, so use inp instead)This takes apart the sentance at the spaces, so the variable "in" is now an array that contains each word in the sentance. I took it a step deeper, and took each word apart and put it back together wrong, but you could just as easily stop at this point an put the whole sentance together wrong.
Code: Select all
 var output = "";
for (i in inp) {
  output  = inp[i] + " " + output;
}

This is fairly simple, it just puts the sentence back together backwards, but you could go into some crazy tower of hanoi recursive fractal type of word reorder. You can use regular expressions to pick out specific words, which, using the above regex, would allow you to do things like pick all consonant-vowel-consonant-anything words and put them in the front of the sentence, with or without mangling the word itself. You can even combine the two, so it's possible to mangle sentence order AND mangle individual words AND substitute both words and letters.

The only thing I can't imagine how to do easily is picking out and reordering based on actual syntactic structure, such as nouns, verbs, adjectives, direct object etc. Understanding human language is hard.

I hope that covered what you were hoping to do. If not, feel free to keep asking. If you can be more clear about what it is that you are in particular looking for, I may be able to help you further :)
B
14
S
5
G
1
Posts: 189
Reputation: 1,536

Next

Return to How do I....?

Who is online

Users browsing this forum: bikachu, irwandwiyanto, thatserafimkid and 3 guests