SA-MP Forums Archive
new Size = sizeof(Message); - 5 Errors - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: new Size = sizeof(Message); - 5 Errors (/showthread.php?tid=440420)



SOLVED : new Size = sizeof(Message); - 5 Errors - S0n1COwnsYou - 29.05.2013

Code:
pawn Код:
stock SendServerMessage(PlayerID,Message[])
{
    new Size = sizeof(Message);
    new TheMessage[Size];
    format(TheMessage,Size,"[SERVER]{FFFFFF} %s",Message);
    SendClientMessage(PlayerID,SexyBlue,TheMessage);
}
Errors:
Код:
C:\Users\S0n1C\Desktop\UA-CNR\gamemodes\UACNR.pwn(683) : warning 224: indeterminate array size in "sizeof" expression (symbol "")
C:\Users\S0n1C\Desktop\UA-CNR\gamemodes\UACNR.pwn(684) : error 008: must be a constant expression; assumed zero
C:\Users\S0n1C\Desktop\UA-CNR\gamemodes\UACNR.pwn(684) : error 009: invalid array size (negative, zero or out of bounds)
C:\Users\S0n1C\Desktop\UA-CNR\gamemodes\UACNR.pwn(684) : error 036: empty statement
C:\Users\S0n1C\Desktop\UA-CNR\gamemodes\UACNR.pwn(684) : fatal error 107: too many error messages on one line



Re: new Size = sizeof(Message); - 5 Errors - Face9000 - 29.05.2013

pawn Код:
format(TheMessage,sizeof TheMessage,"[SERVER]{FFFFFF} %s",Message);



Re: new Size = sizeof(Message); - 5 Errors - S0n1COwnsYou - 29.05.2013

lets say this is right, on creating the variable "TheMessage" wht will be the size ??


Re: new Size = sizeof(Message); - 5 Errors - Face9000 - 29.05.2013

YOU choose it, depends on the length of the message you will send. Use TheMessage[128]; .. it should be good.


Re: new Size = sizeof(Message); - 5 Errors - DobbysGamertag - 29.05.2013

New Size[NUMBER]; will make it the size of the number you put in
pawn Код:
stock SendServerMessage(PlayerID,Message[])
{
    new Size = sizeof(Message);
    new TheMessage[Size]; //i guess the number has to go here.
    format(TheMessage,Size,"[SERVER]{FFFFFF} %s",Message);
    SendClientMessage(PlayerID,SexyBlue,TheMessage);
}



Re: new Size = sizeof(Message); - 5 Errors - IstuntmanI - 29.05.2013

It's better to use just 128:
pawn Код:
stock SendServerMessage(PlayerID,Message[])
{
    new TheMessage[128];
    format(TheMessage, 128,"[SERVER]{FFFFFF} %s", Message);
    SendClientMessage(PlayerID, SexyBlue, TheMessage);
}
or if you really want:
pawn Код:
stock SendServerMessage(PlayerID,Message[])
{
    new Size = strlen(Message), TheMessage[Size];
    format(TheMessage, Size, "[SERVER]{FFFFFF} %s", Message);
    SendClientMessage(PlayerID, SexyBlue, TheMessage);
}



Re: new Size = sizeof(Message); - 5 Errors - Bakr - 29.05.2013

1) Length of "Message" cannot be known from within the function. You need to add another parameter to pass the length of the variable
pawn Код:
stock SendServerMessage(PlayerID, Message[], size = sizeof(Message))
2) Array sizes need to be constant values. You cannot pass a variable for the array size unless it's declared as a constant; which if done inside the function is pointless anyway.


Re: new Size = sizeof(Message); - 5 Errors - Face9000 - 29.05.2013

Quote:
Originally Posted by IstuntmanI
Посмотреть сообщение
or if you really want:
Or:

pawn Код:
#define SCM SendClientMessage

stock SendServerMessage(PlayerID,Message[])
{
    new TM[128];
    format(TM, 128,"[SERVER]{FFFFFF} %s", Message) return SCM(PlayerID, SexyBlue, TM);
}
Not sure if works tbh.


Re: new Size = sizeof(Message); - 5 Errors - Bakr - 29.05.2013

Then why are you posting?

Quote:
Originally Posted by Rules and Guidelines Thread
Do not post untested code.



Re: new Size = sizeof(Message); - 5 Errors - Face9000 - 29.05.2013

Quote:
Originally Posted by Bakr
Посмотреть сообщение
Then why are you posting?
It was just a suggestion.