new Size = sizeof(Message); - 5 Errors
#1

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
Reply
#2

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

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

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

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);
}
Reply
#6

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);
}
Reply
#7

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.
Reply
#8

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.
Reply
#9

Then why are you posting?

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

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


Forum Jump:


Users browsing this thread: 2 Guest(s)