Invalid Memory access
#1

Hello. I was training to create random commands & functions.
I get a strange error.
There is the commands:
PHP Code:
CMD:error(playerid)
{
    
ErrorMessage(playerid"Testing - Name : %s - Level : %i"GetName(playerid), GetPlayerScore(playerid));
    
ErrorMessage(playerid"Blabla"); // -> This line make the command return 0
    
ErrorMessage(playerid"Hi' - Money: %i"GetPlayerMoney(playerid));
    return 
1;
}
ErrorMessage(playerid, const msg[], va_args<>)
{
    new 
string[200];
    
format(stringsizeof(string), "[Erreur] "RED_U"%s"msg);
    
va_format(stringsizeof(string), stringva_start<3>);
    return 
SendClientMessage(playeridREDFstring);
}
GetName(playerid)
{
    static 
str[MAX_PLAYER_NAME];
    
GetPlayerName(playeridstrsizeof(str));
    return 
str;

The command doesnt't work well:
- Logs with the second line:
Code:
[16:49:37] [Erreur] {FF0000}Testing - Nom : cJina_Sawyers - Level : 
[16:49:37] Server: Unknown Command
- Crash detect logs:
Code:
[16:49:37] [debug] Run time error 5: "Invalid memory access"
[16:49:37] [debug] AMX backtrace:
[16:49:37] [debug] #0 00013b58 in ?? (0, 42720) from testing.amx
[16:49:37] [debug] #1 00013a58 in public cmd_error (0, 43596) from testing.amx
[16:49:37] [debug] #2 native CallLocalFunction () from samp-server.exe
[16:49:37] [debug] #3 00013b58 in ?? (0, 42720) from testing.amx
[16:49:37] [debug] #4 00013a58 in public OnPlayerCommandText (0, 43596) from testing.amx
- Without:
Code:
[16:52:13] [Erreur] {FF0000}Testing - Nom : cJina_Sawyers - Level : 
[16:52:13] [Erreur] {FF0000}Hi' - Money:
BUT there is no crash detect logs.

Thanks for your help.
Friendly, Dayrion.
Reply
#2

I'm not sure but replace this line with yours:

PHP Code:
CMD:error(playeridparams[]) 
Reply
#3

Quote:
Originally Posted by Ahmed21
View Post
I'm not sure but replace this line with yours:

PHP Code:
CMD:error(playeridparams[]) 
Same thing

PHP Code:
CMD:error(playerid

    new 
string[100];
    
format(string100"[Erreur] "RED_U"Testing - Name : %s - Level: %d"GetName(playerid), GetPlayerScore(playerid));
    
SendClientMessage(playeridREDFstring);
    
SendClientMessage(playeridREDF"[Erreur] "RED_U"Blabla");
    
format(string100"[Erreur] "RED_U"Hi' - Money: %i"GetPlayerMoney(playerid));
    
SendClientMessage(playeridREDFstring);
    return 
1

Just get rid of Error function, it ain't that easy
Reply
#4

Try this:

PHP Code:
CMD:error(playerid
{
    
ErrorMessage(playerid"Testing - Name : %s - Level : %i"GetName(playerid), GetPlayerScore(playerid)); 
    
ErrorMessage(playerid"Blabla"1-1);
    
ErrorMessage(playerid"Hi' - Money: %i"GetPlayerMoney(playerid)); 
    return 
1

Reply
#5

Quote:
Originally Posted by Ahmed21
View Post
Try this:

PHP Code:
CMD:error(playerid
{
    
ErrorMessage(playerid"Testing - Name : %s - Level : %i"GetName(playerid), GetPlayerScore(playerid)); 
    
ErrorMessage(playerid"Blabla"1-1);
    
ErrorMessage(playerid"Hi' - Money: %i"GetPlayerMoney(playerid)); 
    return 
1

Huh?
Reply
#6

Quote:
Originally Posted by Shinja
View Post
Same thing

PHP Code:
CMD:error(playerid

    new 
string[100];
    
format(string100"[Erreur] "RED_U"Testing - Name : %s - Level: %d"GetName(playerid), GetPlayerScore(playerid));
    
SendClientMessage(playerid, -1string);
    
SendClientMessage(playerid, -1"[Erreur] "RED_U"Blabla");
    
format(string100"[Erreur] "RED_U"Hi' - Money: %i"GetPlayerMoney(playerid));
    
SendClientMessage(playerid, -1string);
    return 
1

Just get rid of Error stock, its more complicated to do like this function
This is not the purpose.

Quote:
Originally Posted by Ahmed21
View Post
Try this:

PHP Code:
CMD:error(playerid
{
    
ErrorMessage(playerid"Testing - Name : %s - Level : %i"GetName(playerid), GetPlayerScore(playerid)); 
    
ErrorMessage(playerid"Blabla"1-1);
    
ErrorMessage(playerid"Hi' - Money: %i"GetPlayerMoney(playerid)); 
    return 
1

Alright, arguments are needed to avoid any crash. Why?
Reply
#7

The problem is that the syntax of the "ErrorMessage" is three parameters: playerid, msg, va_args. But at that problem line (that is returning 0) he entered only two parameters: playerid and message.

So, he must set a default value for the va_arg..
Reply
#8

Quote:
Originally Posted by Ahmed21
View Post
The problem is that the syntax of the "ErrorMessage" is three parameters: playerid, msg, va_args. But at that problem line (that is returning 0) he entered only two parameters: playerid and message.

So, he must set a default value for the va_arg..
Alright thanks for your explication.
I'm looking now, why the fucntion doesn't work well. x.x
Reply
#9

Quote:
Originally Posted by Dayrion
View Post
[php];
ErrorMessage(playerid, "Blabla"); // -> This line make the command return 0
This message doesn't contain arguments, use simple SendClientMessage

Btw is your name really cJina_Sawyers when you tested?
Reply
#10

Quote:
Originally Posted by Shinja
View Post
This message doesn't contain arguments, use simple SendClientMessage

Btw is your name really cJina_Sawyers when you tested?
It was for testing the command and I don't want to use any other function.
Remove the c, it's Jina_Sawyers.

I'm maybe using wrong va_format. The function with debugging:
PHP Code:
ErrorMessage(playerid, const msg[], va_args<>)
{
    static 
strinng[200], second[100];
    
printf("%s - '%s'"msgstrinng);
    
format(secondsizeof(second), "[Erreur] "RED_U"%s"msg);
    print(
second);
    
va_format(strinngsizeof(strinng), secondva_start<3>);
    print(
strinng);
    return 
SendClientMessage(playeridREDFstrinng);

Output:
Code:
[17:48:36] Testing - Nom : %s - Level : %i - ''
[17:48:36] [Erreur] Testing - Nom : %s - Level : %i
[17:48:36] [Erreur] Testing - Nom : cJina_Sawyers - Level :
With SCMF version:
PHP Code:
CMD:error(playerid)
{
    
ErrorMessage(playerid"Testing - Nom : %s - Level : %i"GetName(playerid), GetPlayerScore(playerid));
    
SCMF(playeridREDF"[Erreur] "RED_U"Testing - Nom : %s - Level : %i"GetName(playerid), GetPlayerScore(playerid));
    
//ErrorMessage(playerid, "Blabla");
    //ErrorMessage(playerid, "Hi' - Money: %i", GetPlayerMoney(playerid));
    
return 1;
}
SCMF(playeridcouleur, const msg[], va_args<>)
{
    static 
string[145];
    
va_format(stringsizeof(string), msgva_start<3>);
    return 
SendClientMessage(playeridcouleurstring);

Output:
Code:
[17:48:36] [Erreur] Testing - Nom : cJina_Sawyers - Level : 
[17:48:36] [Erreur] {FF0000}Testing - Nom : Jina_Sawyers - Level : 99
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)