ENIGMA Forums

Outsourcing saves money => Issues Help Desk => Topic started by: intygamer on September 07, 2013, 08:48:31 PM

Title: keyboard_string command
Post by: intygamer on September 07, 2013, 08:48:31 PM
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
Title: Re: keyboard_string command
Post by: Goombert on September 07, 2013, 09:20:08 PM
....

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"
Title: Re: keyboard_string command
Post by: TheExDeus on September 08, 2013, 07:16:08 AM
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.
Title: Re: keyboard_string command
Post by: intygamer on September 08, 2013, 08:55:02 AM
....

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
 
Title: Re: keyboard_string command
Post by: TheExDeus on September 08, 2013, 09:56:39 AM
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.
Title: Re: keyboard_string command
Post by: intygamer on September 08, 2013, 10:33:49 AM
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
Title: Re: keyboard_string command
Post by: TheExDeus on September 08, 2013, 11:24:47 AM
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.
Title: Re: keyboard_string command
Post by: Goombert on September 08, 2013, 11:59:04 AM
@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.
Title: Re: keyboard_string command
Post by: Goombert on September 08, 2013, 12:25:50 PM
@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
Title: Re: keyboard_string command
Post by: intygamer on September 08, 2013, 12:27:15 PM
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
Title: Re: keyboard_string command
Post by: Goombert on September 08, 2013, 12:28:21 PM
Oh, no problem, well at least I added it for Windows now too! :)