SA-MP Forums Archive
Which is better? - 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: Which is better? (/showthread.php?tid=659448)



Which is better? - BlasterDev - 03.10.2018

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;
}



Re: Which is better? - BlasterDev - 03.10.2018

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


Re: Which is better? - [WSF]ThA_Devil - 03.10.2018

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]);


Re: Which is better? - SaMuRy - 03.10.2018

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


Re: Which is better? - [WSF]ThA_Devil - 03.10.2018

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"
};



Re: Which is better? - Nero_3D - 04.10.2018

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