Jump to content


Photo

Typing Game Problem


  • Please log in to reply
15 replies to this topic

#1 Rachel

Rachel

    GMC Member

  • GMC Member
  • 128 posts

Posted 19 February 2012 - 04:29 AM

I'm making a hiragana typing game for Japanese learners. It's going well and I'm nearing the end. There's one issue I've come across. I've been using a chain system to type in characters such as ぴょ (PYO) in which the player would have to hold down all letters at the same time. I did it just because of the limitations of my scripting ability, and it worked fine up until the advanced contracted syllables which most contain three letters. It's just too difficult, and even my husband who's Japanese couldn't beat the advanced level of the game.

What's a script that would just have the player type "p" then "y" then "o"? Instead of having to hold them all down at the same time?

if (image_index = 107) {
if keyboard_check(ord('P')) {
if keyboard_check(ord('Y')) {
if keyboard_check(ord('O')) {
if obj_racing_horse.speed < 3 {
obj_racing_horse.speed = obj_racing_horse.speed+.5
}
hiragana_get = hiragana_get+300
image_index = 0
alarm[0] = 5
}
}
}
else if(keyboard_check(vk_anykey))
{
if obj_racing_horse.speed > .5 {
obj_racing_horse.speed = obj_racing_horse.speed-.5
}
image_index = 0
alarm[0] = 5
}
}

  • 0

#2 Arkaic.ind

Arkaic.ind

    GMC Member

  • GMC Member
  • 76 posts
  • Version:GM8

Posted 19 February 2012 - 04:46 AM

I'm making a hiragana typing game for Japanese learners. It's going well and I'm nearing the end. There's one issue I've come across. I've been using a chain system to type in characters such as ぴょ (PYO) in which the player would have to hold down all letters at the same time. I did it just because of the limitations of my scripting ability, and it worked fine up until the advanced contracted syllables which most contain three letters. It's just too difficult, and even my husband who's Japanese couldn't beat the advanced level of the game.

What's a script that would just have the player type "p" then "y" then "o"? Instead of having to hold them all down at the same time?

if (image_index = 107) {
if keyboard_check(ord('P')) {
if keyboard_check(ord('Y')) {
if keyboard_check(ord('O')) {
if obj_racing_horse.speed < 3 {
obj_racing_horse.speed = obj_racing_horse.speed+.5
}
hiragana_get = hiragana_get+300
image_index = 0
alarm[0] = 5
}
}
}
else if(keyboard_check(vk_anykey))
{
if obj_racing_horse.speed > .5 {
obj_racing_horse.speed = obj_racing_horse.speed-.5
}
image_index = 0
alarm[0] = 5
}
}


Well im not exactly sure what you mean or want but i think i understand your question. You could use the get_string function? not sure what your game looks like
pyo = get_string(word," ");
if pyo = "pyo"
if obj_racing_horse.speed < 3 {
obj_racing_horse.speed = obj_racing_horse.speed+.5
}
hiragana_get = hiragana_get+300
image_index = 0
alarm[0] = 5
}
}
}
else if not pyo = "pyo"
{
if obj_racing_horse.speed > .5 {
obj_racing_horse.speed = obj_racing_horse.speed-.5
}
image_index = 0
alarm[0] = 5
}

then in the create event of the object just put word = 0;
Is this what your looking for? Hope it helps :)

Edited by Arkaic.ind, 19 February 2012 - 04:52 AM.

  • 0

#3 Blake

Blake

    GMC Member

  • GMC Member
  • 443 posts
  • Version:GM:Studio

Posted 19 February 2012 - 04:57 AM

Here's my cheesy way of doing it :tongue:

//STEP EVENT
input = "";
ks = keyboard_string;
for(i = 2; i > -1; i -= 1;)
input += string_char_at(ks,string_length(ks)-i);
if input = "pyo"
{
//do whatever
keyboard_string = "";
}

Edited by Blake, 19 February 2012 - 04:59 AM.

  • 0

#4 Arkaic.ind

Arkaic.ind

    GMC Member

  • GMC Member
  • 76 posts
  • Version:GM8

Posted 19 February 2012 - 05:05 AM

Here's my cheesy way of doing it :tongue:

//STEP EVENT
input = "";
ks = keyboard_string;
for(i = 2; i > -1; i -= 1;)
input += string_char_at(ks,string_length(ks)-i);
if input = "pyo"
{
//do whatever
keyboard_string = "";
}

I like that way better :) I was thinking about that but i didnt know anything about using it haha
  • 0

#5 Rachel

Rachel

    GMC Member

  • GMC Member
  • 128 posts

Posted 19 February 2012 - 05:17 AM

Thank you! Could you explain the script to me? I haven't reached this level of scripting. I will try implementing it into my game.

//STEP EVENT
input = "";
ks = keyboard_string;
for(i = 2; i > -1; i -= 1;)
input += string_char_at(ks,string_length(ks)-i);
if input = "pyo"
{
//do whatever
keyboard_string = "";
}

I don't understand the majority of this script. What does the "i" stand for? What do you mean //do whatever? Do you mean I can put that wherever. How does this code detect that the player is typing?
  • 0

#6 Rachel

Rachel

    GMC Member

  • GMC Member
  • 128 posts

Posted 19 February 2012 - 05:38 AM

I tried both scripts, and they aren't working. Perhaps because I don't understand them, I'm not implementing them correctly.
  • 0

#7 Blake

Blake

    GMC Member

  • GMC Member
  • 443 posts
  • Version:GM:Studio

Posted 19 February 2012 - 05:39 AM

Okay, so the basic idea is that the variable 'input' will contain the last three keyboard keys pressed by the player. The built in variable 'keyboard_string', which we are shortening to the variable 'ks' just to make the code shorter, contains every key that the player has pressed. We only want the last three though. The string_char_at function lets us search for a character/key at any position in 'ks'. So lets say for example that 'ks' contains "abcdef" (meaning that the player has pressed these six keys). We want to only check the last three and store these in the variable 'input', so to do that we use this code:

for(i = 2; i > -1; i -= 1;)
input += string_char_at(ks,string_length(ks)-i);
And... I'm really having trouble explaining in words how this works... um... maybe someone else can help :confused: The bottom line is that input ends up containing the last three keys pressed by the player. So then we check if these last three keys are what the player is supposed to have pressed, in this case, 'pyo'. //do whatever is where you enter your code of what you want to happen when the player presses the correct three keys. At the end, you also must clear the keyboard_string (keyboard_string = "") so that the actions are not repeated over and over again.

I did my best, but it's not the greatest explanation, I know. Sorry, hope it helps a little.

Edited by Blake, 19 February 2012 - 05:40 AM.

  • 0

#8 Arkaic.ind

Arkaic.ind

    GMC Member

  • GMC Member
  • 76 posts
  • Version:GM8

Posted 19 February 2012 - 05:39 AM

Thank you! Could you explain the script to me? I haven't reached this level of scripting. I will try implementing it into my game.

//STEP EVENT
input = "";
ks = keyboard_string;
for(i = 2; i > -1; i -= 1;)
input += string_char_at(ks,string_length(ks)-i);
if input = "pyo"
{
//do whatever
keyboard_string = "";
}

I don't understand the majority of this script. What does the "i" stand for? What do you mean //do whatever? Do you mean I can put that wherever. How does this code detect that the player is typing?

The i deosnt mean anything, it is used in the for statement to create the loop. When he says do whatever he means put the then statement, like do this then this and so on. And i believe it detects when the player is typing because the function keyboard string is called then put into the loop


Edit: Sorry didnt see the last two posts, ignore me :)

Edited by Arkaic.ind, 19 February 2012 - 05:40 AM.

  • 0

#9 GameGeisha

GameGeisha

    GameGeisha

  • GMC Member
  • 2740 posts
  • Version:GM:Studio

Posted 19 February 2012 - 05:47 AM

Maybe if the code is rephrased a little, it would be easier to understand:
//Step event

//Copy out the first three characters from the keyboard input buffer to look at
var input;
input = string_copy(keyboard_string, 1, 3);

//Check it against "pyo"
if (input == "pyo") {
  //Do something...
  keyboard_string = ""; //Clear the input so that further characters can be typed
}

I don't understand the majority of this script. What does the "i" stand for? What do you mean //do whatever? Do you mean I can put that wherever. How does this code detect that the player is typing?

1. In the context of Arkaic.ind's code, the i is known as an iteration variable. Simply put, it counts the number of times that a loop (a repeating statement, in this case a for loop) has run. Without it, the loop simply doesn't know when enough is enough, and when that happens, we refer to it as an infinite loop.
2. // (and similarly /* */ for the equivalent that spans multiple lines) are known as comments. They are text inserted into code that only serve as human-readable instructions or clues (i.e. the runner won't care about them, just you and I). The first comment is telling you to put the code in the step event, and the comment that reads "do something" is telling you to substitute the comment with code that you want to run at that point.
3. keyboard_string is a built-in variable that keeps track of the last 1024 letters, numbers and symbols that the player has typed through the keyboard. By extracting characters off it as shown, we can see what the user has typed and perform actions according to what is there. Functionalities like these can be looked up in the manual (press F1 in GM) in case you run across an unfamiliar one.

GameGeisha
  • 0

#10 Blake

Blake

    GMC Member

  • GMC Member
  • 443 posts
  • Version:GM:Studio

Posted 19 February 2012 - 05:53 AM

//Step event

//Copy out the first three characters from the keyboard input buffer to look at
var input;
input = string_copy(keyboard_string, 1, 3);

//Check it against "pyo"
if (input == "pyo") {
  //Do something...
  keyboard_string = ""; //Clear the input so that further characters can be typed
}

Ahh yes, that's much simpler. I knew my way was cheesy :tongue:
  • 0

#11 Rachel

Rachel

    GMC Member

  • GMC Member
  • 128 posts

Posted 19 February 2012 - 05:53 AM

Thank you, I understand the code better now. But still, it isn't quite working out, because the second half of my code I think is overwriting the intent of the first half.

This is what I implemented into my game (just with one character, the rest follow the old format)

if (image_index = 6) {
for(i = 2; i > -1; i -= 1;)
input += string_char_at(ks,string_length(ks)-i);
if input = "KA"
{
if obj_racing_horse.speed < 3 {
obj_racing_horse.speed = obj_racing_horse.speed+.5
}
hiragana_get = hiragana_get+200
image_index = 0
alarm[0] = 5
}
else if(keyboard_check(vk_anykey))
{
if obj_racing_horse.speed > .5 {
obj_racing_horse.speed = obj_racing_horse.speed-.5
}
image_index = 0
alarm[0] = 5
}
}

If the player typed something other than "ka" (or "pyo" as in the example before), then the horse slows down and it goes onto the next letter. Oh, and that's another thing, sometimes it's two characters, not three. I forgot to adjust the code for that. But it seems to be that the code thinks typing the letter "k" is the wrong letter so it slows the horse down.

I'm going to bed now, but I'll check this forum tomorrow.

Edited by Rachel, 19 February 2012 - 05:54 AM.

  • 0

#12 Blake

Blake

    GMC Member

  • GMC Member
  • 443 posts
  • Version:GM:Studio

Posted 19 February 2012 - 06:03 AM

Okay, so there's 2 things we need to fix.

Firstly, when you check if input is equal to the correct keys, you can't use capital letters because it is case sensitive. So if input = "KA" needs to be changed to if input = "ka".

Secondly, if it's two characters instead of three, we do need to alter the code to deal with that. Lets use GameGeisha's code because it is much simpler. We have this:

var input;
input = string_copy(keyboard_string,1,3);

The last argument in the string_copy needs to be the number of characters you're checking for. So, if you are checking for 'ka' instead of 'pyo', you need to change the 3 to a 2 as 'ka' contains 2 characters.
  • 0

#13 Arkaic.ind

Arkaic.ind

    GMC Member

  • GMC Member
  • 76 posts
  • Version:GM8

Posted 19 February 2012 - 06:16 AM

Okay, so there's 2 things we need to fix.

Firstly, when you check if input is equal to the correct keys, you can't use capital letters because it is case sensitive. So if input = "KA" needs to be changed to if input = "ka".

Secondly, if it's two characters instead of three, we do need to alter the code to deal with that. Lets use GameGeisha's code because it is much simpler. We have this:

var input;
input = string_copy(keyboard_string,1,3);

The last argument in the string_copy needs to be the number of characters you're checking for. So, if you are checking for 'ka' instead of 'pyo', you need to change the 3 to a 2 as 'ka' contains 2 characters.


small addon, if you wanted it to be able to check "KA" and "ka" as the same you chould just make the say something like, if input = "KA" | | input = "ka" this way its saying if it is ka or KA do this. Just thought id throw that out their :)
  • 0

#14 Rachel

Rachel

    GMC Member

  • GMC Member
  • 128 posts

Posted 19 February 2012 - 06:20 AM

//create
input2 = string_copy(keyboard_string,1,2);
input3 = string_copy(keyboard_string,1,3);
ks = keyboard_string;

//step
if (image_index = 6) {
if input2 = "ka"
{
if obj_racing_horse.speed < 3 {
obj_racing_horse.speed = obj_racing_horse.speed+.5
}
hiragana_get = hiragana_get+200
image_index = 0
alarm[0] = 5
}
else if(keyboard_check(vk_anykey))
{
if obj_racing_horse.speed > .5 {
obj_racing_horse.speed = obj_racing_horse.speed-.5
}
image_index = 0
alarm[0] = 5
}
}

When ever the given image for "ka" comes up, it doesn't recognize pressing "k" as part of the "ka" string and goes onto the next character. I think the issue is with the second half of my code vk_anykey.
  • 0

#15 Blake

Blake

    GMC Member

  • GMC Member
  • 443 posts
  • Version:GM:Studio

Posted 19 February 2012 - 06:55 AM

What you have in the create event needs to be in the step event, and you can also get rid of the 'ks = keyboard_string' because with GameGeisha's method we don't need that anymore :thumbsup:
  • 0

#16 Rachel

Rachel

    GMC Member

  • GMC Member
  • 128 posts

Posted 19 February 2012 - 05:51 PM

Still not working. The prompt goes away as soon as I press "k" and I'm not given the chance to press "ka". Would it help if I made a stripped down open source so that you could see the code in action?

Edited by Rachel, 19 February 2012 - 05:51 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users