Which is better?
#1

Option 1:

Код:
enum efuncs
{
 estring[256 char];
}
new func[][efuncs];
{
 {"Text example"},
 {"Text example 2"}
};
or

Option 2:
Код:
GetFunction(id)
{
 new string[256 char];
 switch(id)
 {
   case 1: format(string, sizeof(string), "Text example");
   case 2: format(string, sizeof(string), "Text example 2");
 }
 return string;
}
Reply
#2

I did the examples without thinking, just thinking about which concept to use.
Reply
#3

How about doing this instead?

pawn Код:
new const func[][] =
{
 {"Text example"},
 {"Text example 2"}
};
And later on you just use the array in wherever you want it: SendClientMessage(playerid,-1,func[id]);
Reply
#4

I am not using them both. just use an array better.
Reply
#5

Quote:
Originally Posted by ******
Посмотреть сообщение
No, you still have too many dimensions - why do you need the string in a single-element slot?
Right, I know I'm not the original poster of this, but now you've indeed intrigued me. Have I been doing this wrong for all these years?
What's the other option, because as far as I see it, other than packing the string, there's not much else that can be done.

Obviously, if we're talking about 2 strings in the array, I would not even make an array, where I'd rather resort to an if statement or ternary operator, but in a case of 50 or 100 random messages?

EDIT:

Oh, interesting... I have been doing this wrong all this time. Would've thought that if I was doing it wrong, the compiler might've said anything about the array dimensions not matching or any other weird behaviour happening.

pawn Код:
new const func[][] =
{
 "Text example",
 "Text example 2"
};
Reply
#6

Quote:
Originally Posted by [WSF]ThA_Devil
Посмотреть сообщение
Oh, interesting... I have been doing this wrong all this time. Would've thought that if I was doing it wrong, the compiler might've said anything about the array dimensions not matching or any other weird behaviour happening.

pawn Код:
new const func[][] =
{
 "Text example",
 "Text example 2"
};
That is because the compiler removed the additional braces for you, resulting in the same output
The problem is if you add another dimension (func[][][]) the brace version would still compile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)