inkey and key 'end' memory error

Posted By: Reconnoiter

inkey and key 'end' memory error - 11/20/15 12:09

Hi,

Normally I would ditch inkey and try to find another solution, but since this is a long project which already uses alot of inkeys, I am trying to make the best of it.

Anyway now to my problem: I personally never use the 'end' key when editing textboxes in programs/games, but I noticed that for inkey it gives memory errors (W1516) saying CAT.
My quess would be that is cause I do:
Code:
str_cat(input_str,"                         ");  
inkey(input_str);

to have more space to type. And it doesn't seem to give any problems whatsoever (for like the last 3 months of testing) besides when using 'end' key .
Is there anyway to disable the 'end' key or to prevent this memory error?

tia
Posted By: NeoJones

Re: inkey and key 'end' memory error - 11/20/15 13:13

Puhh I dont know, sorry.
Posted By: NeoJones

Re: inkey and key 'end' memory error - 11/20/15 13:20

Mhh this dont helps?
Code:
if(!key_end)
{
inkey
...
}



Regards, NJ
Posted By: Wjbender

Re: inkey and key 'end' memory error - 11/20/15 13:48

Originally Posted By: Reconnoiter

My quess would be that is cause I do:
Code:
str_cat(input_str,"                         ");  
inkey(input_str);

to have more space to type. And it doesn't seem to give any problems whatsoever (for like the last 3 months of testing) besides when using 'end' key .
Is there anyway to disable the 'end' key or to prevent this memory error?



dont understand why you are doing this .

Code:
//string off 255 spaces
	STRING* input=str_create("#255");
	inkey(input);
	while(1)
	{
		draw_text(input,0,0,COLOR_RED);
		wait(1);
	}

Posted By: txesmi

Re: inkey and key 'end' memory error - 11/20/15 16:01

I always used inchar instead of inkey. Input can be checked and avoid whatever you want.

Code:
void fncModifyString ( STRING *str )
{
	char key[2];
	key[0] = NULL;
	key[1] = NULL;
	while ( 1 )
	{
		var nKey = inchar ( NULL );
		if ( nKey == 8 )
		{
			if ( !key[0] )
			{
				str_cpy ( str, "" );
				txtCursor->pos_x = panHscores->pos_x + MC_HIGHSCORE_BORDER_SIZE_X;
			}
			else
			{
				str_trunc ( str, 1 );
				txtCursor->pos_x = panHscores->pos_x + MC_HIGHSCORE_BORDER_SIZE_X + str_width ( str, fntHscores );
				int count = str_len ( str );
				while ( str_getchr ( str, count ) == 32 )
				{
					count -= 1;
					txtCursor->pos_x += str_width ( "t", fntHscores );
				} 
			}
		}
		else if ( nKey == 13 )
		{
			if ( str_len ( str ) == 0 )
				str_cpy ( str, MC_HIGHSCORE_NAME );
			break;
		}
		else if ( nKey == 27 )
		{
			str_cpy ( str, MC_HIGHSCORE_NAME );
			break;
		}
		else if ( str_len ( str ) > MC_HIGHSCORE_MAX_CHARS )
		{
			continue;
		}
		else if ( nKey < 32 )
		{
			continue;
		}
		else
		{
			if ( !key[0] )
			{
				str_cpy ( str, "" );
				txtCursor->pos_x = panHscores->pos_x + MC_HIGHSCORE_BORDER_SIZE_X;
			}
			key[0] = nKey;
			str_cat ( str, key );
			if ( nKey == 32 )
				txtCursor->pos_x += str_width ( "t", fntHscores );
			else
				txtCursor->pos_x += str_width ( key, fntHscores );
		}
	}
}

Posted By: Reconnoiter

Re: inkey and key 'end' memory error - 11/20/15 16:40

thanks guys I will try these things
Posted By: Reconnoiter

Re: inkey and key 'end' memory error - 11/27/15 13:23

Quote:
dont understand why you are doing this .

Code:

//string off 255 spaces
STRING* input=str_create("#255");
inkey(input);
while(1)
{
draw_text(input,0,0,COLOR_RED);
wait(1);
}
, how to get this working if you are using a global string?

globally initializing STRING* input_str = "#100"; doesnt work right when I am editing it with inkey and I have no extra space to write letters/numbers.
Posted By: Anonymous

Re: inkey and key 'end' memory error - 11/27/15 18:22

in_key overwrites the string and can not exceed the string length. It's also a internal wait, I assume it can not draw_x till the internal wait is terminated. But I don't understand your issue. I'll put it on my testing list for later today, if you haven't solved it by then.

EDIT- You code works fine... As I believed, it draw text as soon as you hit (enter) the termination key. Due to the loop, only a TEXT* object can show the active entry of the inkey.
My test code
Code:
STRING* input_me="#228";

///////////////////////////////
function main()
{
  vec_set(screen_size,vector(800,400,0));
  vec_set(screen_color,vector(50,1,1)); // dark blue
  vec_set(sky_color,vector(50,1,1)); // dark blue
  video_window(NULL,NULL,0,"My New Game");
  inkey(input_me);
  while(1)
  {
  	draw_text(input_me,50,50,COLOR_WHITE);
  	wait(1);
}




Mal
Posted By: Wjbender

Re: inkey and key 'end' memory error - 11/27/15 18:46

Originally Posted By: Reconnoiter
Quote:
dont understand why you are doing this .

Code:

//string off 255 spaces
STRING* input=str_create("#255");
inkey(input);
while(1)
{
draw_text(input,0,0,COLOR_RED);
wait(1);
}
, how to get this working if you are using a global string?

globally initializing STRING* input_str = "#100"; doesnt work right when I am editing it with inkey and I have no extra space to write letters/numbers.


there's no need for global initialization .

Code:
//global level
STRING *glob_str;

//some function
void foo ()
{
     glob_str=str_create ("#100");
}



what I don't understand is when you write "extra space" , because if you initialize with #100 it means you have a string that can take 100 characters .

do you mean you want to write blank spaces in the string or do you mean you want to resize the string length?
Posted By: Anonymous

Re: inkey and key 'end' memory error - 11/27/15 18:49

I think your error from your first post is a access error. The internal loop and locking of the string.
Anyway use 2 strings , something like this...
Code:
STRING* str_ret="";
STRING* input_str="#256"

str_cat(str_ret,"                             ");
inkey(input_str);
str_cat(str_ret,input_str);
while(1)
{
 draw_text(str_ret,50,50,COLOR_WHITE);
wait(1);
}



Anyways I'm a bit confused and firing into the dark, so if I'm off track here. Sorry
Mal
Posted By: Reconnoiter

Re: inkey and key 'end' memory error - 11/28/15 13:05

Well I use the inkey to edit textboxes etc in the game. Before doing inkey I copy the current string of the textbox to the input string. But when I do that it seems to be byebye to the #100 / 100 characters of the input string.
Posted By: Anonymous

Re: inkey and key 'end' memory error - 11/28/15 14:28

Yes indeed, inkey is limited to the size of the string. If you change the sting size you clip inkey. But even more copying the textbox->characters into the input is pointless, as inkey, should start at the first character location and overwrite the whole string.
Posted By: Anonymous

Re: inkey and key 'end' memory error - 11/28/15 15:11


Code:
STRING* str_input;
STRING* str_temp;
STRING* str_flush_buffer="#100";
STRING* str_textbox[10];

function fill_textboxs()
{
  int I;
 for(I=0;i<10;i++)
    {
       str_textbox[I]=str_create("");
     }
}

function str_mod()
{
int int_str_len;

str_cpy(str_input,str_flush_buffer); // Clear the input
int_str_len=str_len(str_textbox[0]); // Find current len of textbox
str_cpy(str_temp,str_textbox[0]);    // move textbox into temp/ or use a textbox_dply[array size of textbox]
str_cat(str_temp,str_flush_buffer);  // add the maximun input len of white spaces
str_trunc(str_temp,int_str_len);     // cut textbox len of white spaces off end of temp
str_cpy(str_input,str_temp);         // fill the input text + white_space trunced to max 
inkey(str_input);                    // Edit text
str_cpy(str_textbox[0],str_input);   // replace text in texbox
int_str_len=str_len(str_textbox[0]); // degubbing only
}




Not sure how this works but it's an idea to work from

Mal
Posted By: Reconnoiter

Re: inkey and key 'end' memory error - 12/01/15 13:19

lol, I think I found a really funny solution with your help Malice, doing this after having copied content of current textbox string and before doing inkey(...):

Code:
str_cat(input_str, str_flush_buffer); //add spaces
str_trunc(input_str, 1); //removes point of memory error



I am not sure if this is bulletproof though. I mean in the world of memory errors it would be best to not use it blindly. So far after some testing it seems good though.
Posted By: Anonymous

Re: inkey and key 'end' memory error - 12/01/15 17:24

LOl - That's how it works with my help more often then not. I spit fire blind ideas and smart people find something useful in it.
It is a odd solution, I'd love to hear jcl explain why it works and throws a error without.

Mal
© 2024 lite-C Forums