|
inkey and key 'end' memory error
#456366
11/20/15 12:09
11/20/15 12:09
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
OP
Serious User
|
OP
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
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:
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
Last edited by Reconnoiter; 11/20/15 12:10.
|
|
|
Re: inkey and key 'end' memory error
[Re: NeoJones]
#456368
11/20/15 13:20
11/20/15 13:20
|
Joined: Dec 2010
Posts: 224 NRW, Germany
NeoJones
Member
|
Member
Joined: Dec 2010
Posts: 224
NRW, Germany
|
Mhh this dont helps?
if(!key_end)
{
inkey
...
}
Regards, NJ
Errors are the engine of progress.
Version: A8 Commercial OS: Win 7 64bit Models: Cinema 4D
|
|
|
Re: inkey and key 'end' memory error
[Re: Reconnoiter]
#456369
11/20/15 13:48
11/20/15 13:48
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
My quess would be that is cause I do:
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 .
//string off 255 spaces
STRING* input=str_create("#255");
inkey(input);
while(1)
{
draw_text(input,0,0,COLOR_RED);
wait(1);
}
Compulsive compiler
|
|
|
Re: inkey and key 'end' memory error
[Re: Wjbender]
#456371
11/20/15 16:01
11/20/15 16:01
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
I always used inchar instead of inkey. Input can be checked and avoid whatever you want.
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 );
}
}
}
|
|
|
Re: inkey and key 'end' memory error
[Re: Reconnoiter]
#456534
11/27/15 13:23
11/27/15 13:23
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
OP
Serious User
|
OP
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
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.
|
|
|
Re: inkey and key 'end' memory error
[Re: Reconnoiter]
#456540
11/27/15 18:22
11/27/15 18:22
|
Malice
Unregistered
|
Malice
Unregistered
|
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
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
Last edited by Malice; 11/27/15 18:40.
|
|
|
Re: inkey and key 'end' memory error
[Re: Reconnoiter]
#456542
11/27/15 18:46
11/27/15 18:46
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
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 .
//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?
Compulsive compiler
|
|
|
Re: inkey and key 'end' memory error
[Re: ]
#456543
11/27/15 18:49
11/27/15 18:49
|
Malice
Unregistered
|
Malice
Unregistered
|
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...
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
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|