Page 1 of 1

Suspicious pointer error :D?

PostPosted: Mon Nov 14, 2011 2:05 pm
by Hblade
strcpy(CHAONAME, strlen(CHAONAME)-1);

This gives me an error ^^ Anyone mind helping out? I'm trying to make a "backspace" button haha.

Code: Select all

     sprintf(CHAONAME, "%s", strlen(CHAONAME)-1);


This code crashes GE XDD

Re: Suspicious pointer error :D?

PostPosted: Mon Nov 14, 2011 2:44 pm
by lcl
strlen() returns an integer, not a string, so your code should be:
Code: Select all
sprintf(CHAONAME, "%i", strlen(CHAONAME)-1);

:D

Re: Suspicious pointer error :D?

PostPosted: Mon Nov 14, 2011 2:48 pm
by Hblade
lcl wrote:strlen() returns an integer, not a string, so your code should be:
Code: Select all
sprintf(CHAONAME, "%i", strlen(CHAONAME)-1);

:D

Thhhanks! :D +1

Edit: LOL now all it does is change the text actor to "however many letters in the string" XD then 0 O-o

Re: Suspicious pointer error :D?

PostPosted: Mon Nov 14, 2011 2:57 pm
by lcl
Yeah, lol I understood your problem just after posting that. I'm now solving it for you. :)

EDIT: It first seemed that you wanted just to show the amount of characters and that's why I got confused. :D

Re: Suspicious pointer error :D?

PostPosted: Mon Nov 14, 2011 3:00 pm
by lcl
Here ya go:
Code: Select all
CHAONAME[strlen(CHAONAME) - 1 * (strlen(CHAONAME) > 0)] = NULL;

The * (strlen(...)) part is for that otherwise it'd try to set CHAONAME[- 1] equal to NULL when strlen is 0. And that naturally causes error.
:)

Re: Suspicious pointer error :D?

PostPosted: Mon Nov 14, 2011 3:07 pm
by Hblade
Thanks dood!

but it keeps the first letter D: I think I can fix this though ^^

Well, it keeps it lol but it gets overwritten so its good :D

Thanks a bunch man! :D

Fixed ^^

Re: Suspicious pointer error :D?

PostPosted: Mon Nov 14, 2011 3:09 pm
by lcl
Hblade wrote:Thanks dood!

but it keeps the first letter D: I think I can fix this though ^^

I found this problem too, but you can get around of it by changing you sprintf() to strcpy(). (The one that shows your CHAONAME. :D)

EDIT:
Thought to explain more accurately.. :D

So, like:
Code: Select all
strcpy(text, CHAONAME);


It seems that for some reason, the sprintf() doesn't work with the actors text all that well compared to strcpy().
I don't really know why it works only with strcpy():

EDIT 2: :lol:
Hblade wrote:Well, it keeps it lol but it gets overwritten so its good

That sounds like spritntf() doesn't refresh the text actors text as it should, because while I was testing my code, another text actor showed that string was empty, but the one I was erasing showed still the first letter..

Re: Suspicious pointer error :D?

PostPosted: Mon Nov 14, 2011 3:46 pm
by Hblade
Yeah but I fixed it now =) I added a simpel if script
Code: Select all
if(strlen(CHAONAME)>0) {
//make chaos name appear }
else {
//eithe rmake the text blank, but in my case change the text to "NO_NAME"
}

the text "NO_NAME" does not effect the CHAONAME varaible =)