Pages: 1
  Print  
Author Topic: keyboard_string command  (Read 2238 times)
Offline (Unknown gender) intygamer
Posted on: September 07, 2013, 08:48:31 PM

Member
Joined: Mar 2013
Posts: 77

View Profile Email
Hi
I am trying to use keyboard_string command to input information.  I can not use get_string because of gtk problem with Ubuntu.

Typing in a name and then enter will not stop the input of info, it's like it wants to input all 1024 characters it excepts.

In draw event

Code: [Select]
draw_text(10,20,"Enter your name here: "+string(keyboard_string));
if (keyboard_check_pressed(vk_enter))
{
alarm[0];
}

Please let me know what I'm doing wrong.

Thanks
Joe
Logged
Offline (Male) Goombert
Reply #1 Posted on: September 07, 2013, 09:20:08 PM

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 3110

View Profile
....

Ok, so that explains why it isn't working on Linux after I thought I fixed it. Remove string() from around it. Also get_string requires you set Build->Settings and set the widget system under "API"

If removing string() don't fix your problem I will make an attempt at fixing it from Windows. Also Linux is not called "Linux" under SHELL/platforms it is called "Xlib"
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Unknown gender) TheExDeus
Reply #2 Posted on: September 08, 2013, 07:16:08 AM

Developer
Joined: Apr 2008
Posts: 1872

View Profile
I don't think keyboard_string is even implemented. Some while ago I added keyboard_lastchar so that works (and can be used to create a textbox you want), but I don't think we have keyboard_string. At least on Windows it doesn't work.

Even if it did work, why would that code stop inputing text when enter is pressed? You call an alarm event, you don't stop keyboard_string from populating. If you want that, then do something like this:
Code: [Select]
if (input_done == false){ draw_text(10,20,"Enter your name here: "+string(keyboard_string)); }
else { draw_text(10,20,"Enter your name here: "+string(name)); }
if (keyboard_check_pressed(vk_enter))
{
name = keyboard_string;
input_done = true;
alarm[0];
}

edit: Unless you meant that "Enter" should automatically clear the keyboard_string. That shouldn't be true in GM either. It just shows the last 1024 chars pressed. Enter will probably add a newline character, but it will not delete the previous ones. If you want keyboard_string to clear, then set it to an empty string.
« Last Edit: September 08, 2013, 07:19:02 AM by TheExDeus » Logged
Offline (Unknown gender) intygamer
Reply #3 Posted on: September 08, 2013, 08:55:02 AM

Member
Joined: Mar 2013
Posts: 77

View Profile Email
....

Ok, so that explains why it isn't working on Linux after I thought I fixed it. Remove string() from around it. Also get_string requires you set Build->Settings and set the widget system under "API"

If removing string() don't fix your problem I will make an attempt at fixing it from Windows. Also Linux is not called "Linux" under SHELL/platforms it is called "Xlib"

I removed string() it still did work.

Code: [Select]
draw_text(10,20,"Enter your name here: "+keyboard_string);
if (keyboard_check_pressed(vk_enter))
{
alarm[0];
}

Also tried TheEXDeus code as is and without string().

I don't think keyboard_string is even implemented. Some while ago I added keyboard_lastchar so that works (and can be used to create a textbox you want), but I don't think we have keyboard_string. At least on Windows it doesn't work.

Even if it did work, why would that code stop inputing text when enter is pressed? You call an alarm event, you don't stop keyboard_string from populating. If you want that, then do something like this:
Code: [Select]
if (input_done == false){ draw_text(10,20,"Enter your name here: "+string(keyboard_string)); }
else { draw_text(10,20,"Enter your name here: "+string(name)); }
if (keyboard_check_pressed(vk_enter))
{
name = keyboard_string;
input_done = true;
alarm[0];
}

edit: Unless you meant that "Enter" should automatically clear the keyboard_string. That shouldn't be true in GM either. It just shows the last 1024 chars pressed. Enter will probably add a newline character, but it will not delete the previous ones. If you want keyboard_string to clear, then set it to an empty string.

I tried your code as is and without string() after pressing enter it does not go to alarm event.  After the 1st enter press you can not see any more typing till you hit enter. 

Thanks
Joe
 
Logged
Offline (Unknown gender) TheExDeus
Reply #4 Posted on: September 08, 2013, 09:56:39 AM

Developer
Joined: Apr 2008
Posts: 1872

View Profile
Quote
I tried your code as is and without string() after pressing enter it does not go to alarm event.  After the 1st enter press you can not see any more typing till you hit enter. 
That is actually because alarm[0] doesn't do anything. To use alarms you must set the value after which the alarm event will run. I didn't notice that before in your code, but you must do this:
Code: [Select]
alarm[0]=1;to run the alarm after 1 step. The reason why it didn't show anything typing is because I update the string only when enter is pressed. Anyway, I am still confused why keyboard_string works for you as it doesn't on windows.
Logged
Offline (Unknown gender) intygamer
Reply #5 Posted on: September 08, 2013, 10:33:49 AM

Member
Joined: Mar 2013
Posts: 77

View Profile Email
Quote
I tried your code as is and without string() after pressing enter it does not go to alarm event.  After the 1st enter press you can not see any more typing till you hit enter. 
That is actually because alarm[0] doesn't do anything. To use alarms you must set the value after which the alarm event will run. I didn't notice that before in your code, but you must do this:
Code: [Select]
alarm[0]=1;to run the alarm after 1 step. The reason why it didn't show anything typing is because I update the string only when enter is pressed. Anyway, I am still confused why keyboard_string works for you as it doesn't on windows.

I made the change and it will not go to the alarm event.

Code: [Select]
if (input_done = 0){ draw_text(10,20,"Enter your name here: "+string(keyboard_string)); }
else { draw_text(10,20,"Enter your name here: "+string(name)); }
if (keyboard_check_pressed(vk_enter))
{
name = keyboard_string;
input_done = 1;
alarm[0] = 1;
}

Alarm 0 code

Code: [Select]
if (name = ' ')
{
room_restart;
}
else
{
room_goto_next;
}

Thanks!
Joe
Logged
Offline (Unknown gender) TheExDeus
Reply #6 Posted on: September 08, 2013, 11:24:47 AM

Developer
Joined: Apr 2008
Posts: 1872

View Profile
room_restart and room_goto_next are functions, not variables. You need to have them like room_restart() and room_goto_next(). Is this your first time with GM/ENIGMA or programming? I think for GM there are some very good intro courses, but I just learned from examples. Remember recreating that 1945 plane game from scratch in GM when I was 12 or something. Couldn't remember whether x was horizontal or vertical position.

edit: Also, just for information - When using functions without parenthesis (so just the function name and not really calling a function) returns the function "id". In GM I think this breaks it, but in ENIGMA you can pass functions to scripts and such (at least theoretically). In C++ this would be a pointer. It doesn't work right now in ENIGMA either as we can't use pointers. I know that in GM (and ENIGMA) you can use scripts like this though. Like have a script scr_explode() and scr_explode_large(), then in create event write explosion_script = scr_explode; and then script_execute(explosion_script). This is possible because in these cases only resource id's are used and not pointers.
« Last Edit: September 08, 2013, 11:32:34 AM by TheExDeus » Logged
Offline (Male) Goombert
Reply #7 Posted on: September 08, 2013, 11:59:04 AM

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 3110

View Profile
@Harri, I added for Linux, I'll commit it for Windows too.

https://github.com/enigma-dev/enigma-dev/search?q=keyboard_string&ref=cmdform

Code: [Select]
enigma_user::keyboard_string += enigma_user::keyboard_lastchar;

if (enigma::last_keybdstatus[actualKey]==1 && enigma::keybdstatus[actualKey]==0) {

@intygamer, your on Windows right? or are you on Linux? Because it should work on Linux I have to go add it right now for Windows.
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Male) Goombert
Reply #8 Posted on: September 08, 2013, 12:25:50 PM

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 3110

View Profile
@intygamer/Harri here I implemented it for Windows, somebody please merge my pull request on GitHub...
https://github.com/enigma-dev/enigma-dev/pull/384
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Unknown gender) intygamer
Reply #9 Posted on: September 08, 2013, 12:27:15 PM

Member
Joined: Mar 2013
Posts: 77

View Profile Email
room_restart and room_goto_next are functions, not variables. You need to have them like room_restart() and room_goto_next(). Is this your first time with GM/ENIGMA or programming? I think for GM there are some very good intro courses, but I just learned from examples. Remember recreating that 1945 plane game from scratch in GM when I was 12 or something. Couldn't remember whether x was horizontal or vertical position.

edit: Also, just for information - When using functions without parenthesis (so just the function name and not really calling a function) returns the function "id". In GM I think this breaks it, but in ENIGMA you can pass functions to scripts and such (at least theoretically). In C++ this would be a pointer. It doesn't work right now in ENIGMA either as we can't use pointers. I know that in GM (and ENIGMA) you can use scripts like this though. Like have a script scr_explode() and scr_explode_large(), then in create event write explosion_script = scr_explode; and then script_execute(explosion_script). This is possible because in these cases only resource id's are used and not pointers.

Duh I forgot the () for the functions.  It works  :)  Thanks for your help TheExDeus.
I was using drag and drop now tring just to write code instead, better for copy and paste.  I do have the 1945 plane example.

@Harri, I added for Linux, I'll commit it for Windows too.

https://github.com/enigma-dev/enigma-dev/search?q=keyboard_string&ref=cmdform

Code: [Select]
enigma_user::keyboard_string += enigma_user::keyboard_lastchar;

if (enigma::last_keybdstatus[actualKey]==1 && enigma::keybdstatus[actualKey]==0) {

@intygamer, your on Windows right? or are you on Linux? Because it should work on Linux I have to go add it right now for Windows.

I have Ubuntu Linux.  TheExDeus helped me fix my code and now it works.   :)  Thanks for help Robert.

Thanks!
Joe
Logged
Offline (Male) Goombert
Reply #10 Posted on: September 08, 2013, 12:28:21 PM

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 3110

View Profile
Oh, no problem, well at least I added it for Windows now too! :)
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Pages: 1
  Print