Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Joseph on Mon 28/09/2009 23:18:43

Title: Limit the length of save name sentence
Post by: Joseph on Mon 28/09/2009 23:18:43
Hi DUDES...

I wont even pretend I know where to start on this one...so Ill just say what I want to get done, somehow...I figure it has to do with the length property though:


Length property
(Formerly known as global function StrLen, which is now obsolete)

readonly int String.Length;

Returns the length of the string, in characters.
Example:

String text = "This is my string.";
Display("Length: %d", text.Length);



What Im trying to do is limit the player's save game names to a certain length, like I dont want people to be able to save titles longer than say...10 characters (for example).

How would I go about making this a reality?

PS: I pee in the shower
Title: Re: Limit the length of save name sentence
Post by: RickJ on Tue 29/09/2009 02:36:37
I think this is what you want ...

Quote from: AGS Manual
String.Truncate(int length)

Returns a version of the string that has been truncated down to length characters.

NOTE: The new string is returned from this funcAtion; it does NOT modify the original string.

Example:

String mystring = "Hello World!";
String truncated = mystring.Truncate(4);
Display("Original: %s, Truncated: %s", mystring, truncated);

will display "Original: Hello World!, Truncated: Hell".

See Also: String.Append, String.Substring
Title: Re: Limit the length of save name sentence
Post by: Wonkyth on Tue 29/09/2009 09:04:58
You could probably do something with ClaimEvent...
Title: Re: Limit the length of save name sentence
Post by: monkey0506 on Tue 29/09/2009 19:09:20
ClaimEvent really wouldn't be relevant. ClaimEvent is for preventing other scripts from handling certain events like on_mouse_click and on_key_press.

What Joseph is wanting to do is limit the number of characters available for save game names. So he would want to do something like:

// global script
function repeatedly_execute() {
  if (gSave.Visible) {
    if (txtSavename.Text.Length > 10) txtSavename.Text = txtSavename.Text.Truncate(10);
  }
}


That way if the user tried to type in more than 10 characters into the save name text box, the text would be automatically truncated down to only 10 characters.
Title: Re: Limit the length of save name sentence
Post by: Joseph on Tue 29/09/2009 22:10:41
Ok these are all great tricks...I will try em out.

However, its not exactly what I was meaning, but I think I just thought of somethin that might work:

When the player enters a savegame name (for example I Love Turtles), instead of truncating the I Love Turtles to 10 characters...I will have a dialog pop-up saying "please limit your save names to 10 characters or less"...the reason for this is I dont want characters overlapping over my gui window thing...it can only display 10 characters cause thtas the way I like it!

Ill just do an "if/else" thing to check the length of the inputted text I guess.

I like the truncate (10) command though...and will try that too if I cant get the other way to work.
Title: Re: Limit the length of save name sentence
Post by: monkey0506 on Wed 30/09/2009 03:58:51
You could call truncate and then at the same time call a Display command to let the player know what's happening (as if it's not obvious). Just put braces around both commands and throw it in with the code above.

If you don't truncate the text if it exceeds the limit then you're not actually enforcing the limit and just suggesting it. So the truncate command should be considered more vital than just the Display. ;)