InputReadString

InputReadString
string InputReadString(string current_string, int max_length)

Documentation

Check for cursor_pos equalling -1 as the input confirmed.

There may have a minor bug at the moment, where input can reverse. Possibly replated to a bad cursor_pos value being taken.

Example Usage

string InputReadString(string current_string, int max_length)
// Pass: Variable name of string, Maximum allow characters
// Returns: The string after input
// Requires: Global int cursor_pos
{
	UpdateControls(); // Just In Case
	if(key[SCAN_BACKSP]) // Delete chr before cursor
	{
		lastpressed = 0;
		key[SCAN_BACKSP] = 0;
		if (cursor_pos > 0) // If there is a chr before the cursor
		{
			max_length = len(current_string) - cursor_pos;
			cursor_pos--;
			return left(current_string, cursor_pos)
				+ right(current_string, max_length);
		}
	}
	else if(key[SCAN_DEL] || key[211]) // Delete chr after cursor
	{
		lastpressed = 0;
		key[SCAN_DEL] = 0; // Num pad DEL key
		key[211] = 0; // Delete key
		// If there is a chr after the cursor
		if (cursor_pos < len(current_string))
		{
			max_length = len(current_string) - cursor_pos - 1;
			return left(current_string, cursor_pos)
				+ right(current_string, max_length);
		}
	}
	else if(key[SCAN_ENTER]) // Input completed
	{
		lastpressed = 0;
		cursor_pos = -1; // Check for -1 as a confirm of string input
	}
	else if(key[SCAN_TAB]) // Move to next input
	{
		key[SCAN_TAB] = 0;
		cursor_pos = -1; // Check for -1 as a input move
	}
	else if(key[SCAN_UP]) // Up to start of string
	{
		key[SCAN_UP] = 0;
		cursor_pos = 0;
	}
	else if(key[SCAN_DOWN]) // Down to end of string
	{
		key[SCAN_DOWN] = 0;
		cursor_pos = len(current_string);
	}
	else if(key[SCAN_LEFT]) // Move cursor left one space
	{
		key[SCAN_LEFT] = 0;
		if (cursor_pos > 0) cursor_pos--;
	}
	else if(key[SCAN_RIGHT]) // Move cursor right one space
	{
		key[SCAN_RIGHT] = 0;
		if (cursor_pos < len(current_string)) cursor_pos++;
	}
	else if(lastpressed)
	{
		lastpressed = 0;
		if(key[SCAN_V]) // Move cursor right one space
		{
			if (key[SCAN_CTRL] && len(clipboard.text))
			{
				key[SCAN_V] = 0;
				cursor_pos = len(clipboard.text);
				if (cursor_pos > max_length)
				{
					cursor_pos = max_length;
					return left(clipboard.text, max_length);
				}
				else return clipboard.text;
			}
		}
		// If it's a string-able chr, and string is not too long
		if (len(chr(lastkey)) && len(current_string) < max_length)
		{
			max_length = len(current_string) - cursor_pos;
			cursor_pos++;
			return left(current_string, cursor_pos - 1) + chr(lastkey)
				+ right(current_string, max_length);
		}
	}
	lastpressed = 0;
	return current_string;
}
Talkback

There are no talkbacks on this documentation page yet. Post the first?

Post a new comment?

Doc Nav

Your docs
View All Docs

If you log in, you can edit the documentation, or create your own documents and tutorials!

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.