• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Remove last character from a string

T

tamation

Guest
I'm really struggling with setting typing limitations right now. Ideally I'd like to have it so that once the player's keyboard_string exceeds a width of 248 pixels, they can't type anything else to add to the string until some characters have been removed.

I couldn't figure out how to stop keyboard_string from receiving inputs, so I tried to set a limit for the string width instead, and when it is exceeded have it automatically remove the most recent character you typed.

This is what I have so far:

currentstring = string_width(keyboard_string);

lastchar = string_pos(keyboard_lastchar,keyboard_string);

if currentstring > 248 { string_delete(keyboard_string,lastchar,1) }

I've been trying a few different set-ups with it, but I've had absolutely no luck so far. Any help or tips on a better system of limiting the width of keyboard_string would be greatly appreciated.
 

FrostyCat

Redemption Seeker
string_delete() returns a copy of the string that has the specified portion removed, it doesn't operate in-place.
The Manual entry for string_delete() said:
and the function will return a new string without that section in it.
Code:
if (currentstring > 248) {
  keyboard_string = string_delete(keyboard_string, lastchar, 1);
}
 
T

tamation

Guest
string_delete() returns a copy of the string that has the specified portion removed, it doesn't operate in-place.

Code:
if (currentstring > 248) {
  keyboard_string = string_delete(keyboard_string, lastchar, 1);
}
Ahhh, my bad, sorry. That was the issue with removing characters, thank you. Is there a better way of locating the last character in a string? The lastchar variable checks keyboard_lastchar, which has a habit of deleting other occurrences of the character in the string, even when they're not at the end.
 

FrostyCat

Redemption Seeker
With the first character of a string at position 1, the last character is at position string_length().

Either do this:
Code:
keyboard_string = string_delete(keyboard_string, string_length(keyboard_string), 1);
Or this:
Code:
keyboard_string = string_copy(keyboard_string, 1, string_length(keyboard_string)-1);
 
T

tamation

Guest
With the first character of a string at position 1, the last character is at position string_length().

Either do this:
Code:
keyboard_string = string_delete(keyboard_string, string_length(keyboard_string), 1);
Or this:
Code:
keyboard_string = string_copy(keyboard_string, 1, string_length(keyboard_string)-1);
Thank you so much!
 
Top