GameMaker [Solved]Storing keyboard_string in two variables with different length

I'm having trouble wrapping my brain around strings, and especially how string_delete works.

I'm trying to store characters from keyboard_string in two different variables with different lenghts. One of the variables is used to store only 1 character (output), which refreshes everytime something new is put into keyboard_string, while I want (variable - not yet made) to just store the whole keyboard_string. So far I've tried several approaches, but I think I don't quite grasp how string_delete works. Here's the code:

Code:
input = keyboard_string;
output = string_delete(input, 1, 1);

if string_length(output) > 1
      {
      output = string_delete(output, 1, 1);
      }
This is just my latest approach, which seems to work for the first two times an input is made, but then the string (output) just adds numbers to itself, instead of adding and subtracting, going beyond 2 breaking the code.

Any ideas would be much appreciated?
 
Last edited:
E

Edwin

Guest
keyboard_string stores only 1 character which is the last key you've pressed. You don't need to create a new variable and delete the last character. Just reflesh keyboard_string every end of the Step.
Code:
output += keyboard_string;
keyboard_string = "";
 
keyboard_string stores only 1 character which is the last key you've pressed. You don't need to create a new variable and delete the last character. Just reflesh keyboard_string every end of the Step.
Code:
output += keyboard_string;
keyboard_string = "";
I've updated to OP, to better reflect what I want to do.

I want (output) to only store one character, which is updated with a new character, everytime something new is put into keyboard_string (but only the most recent character).
 
E

Edwin

Guest
I've updated to OP, to better reflect what I want to do.

I want (output) to only store one character, which is updated with a new character, everytime something new is put into keyboard_string (but only the most recent character).
keyboard_string stores 1 character, you don't need to delete characters from output. Just do this:
Code:
output = keyboard_string;
 
I think you have to elaborate for me to understand.

If I draw keyboard_string in the GUI it grows by one character each time I input something through the keyboard.
 
Top