SA-MP Forums Archive
2d array with different value types - 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: 2d array with different value types (/showthread.php?tid=611698)



2d array with different value types - Jonesy96 - 09.07.2016

Hi all,

I need to create a 2d array with different variable types within it. That doesn't really explain what Im trying to do very well, but hopefully my attempt below may describe what im trying to do.

Код:
//I want an array which has both and integer value and a string value inside of it. 
myArray[0] =>[0]=>1
myArray[0] =>[1]=>"This string"

myArray[1] =>[0]=>2
myArray[1] =>[1]=>"Another string"
I know the above isn't PAWN code obviously, however I hope you can see the jyst of what I want.

Thanks in advance for any help.


Re: 2d array with different value types - SickAttack - 09.07.2016

Enumerators

https://sampforum.blast.hk/showthread.php?tid=318307


Re: 2d array with different value types - paulommu - 09.07.2016

Yep. Enumerators.

Код:
enum MyEnumerator
{
    enumInteger,
    enumString[32]
};
new MyArray[][MyEnumerator] = {
    {1, "This string"},
    {2, "Another string"}
};

MyArray[0][enumInteger] => 1
MyArray[1][enumString] => "Another string"



Re: 2d array with different value types - Gammix - 09.07.2016

If you are going serial wise, you can make use of the index id itself.

pawn Код:
myArray[0] =>"This string"
(index => 0 + 1 => 1)

myArray[1] =>"Another string"
(index => 1 + 1 => 2)