SA-MP Forums Archive
Looping Through multi-dimensional array - 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: Looping Through multi-dimensional array (/showthread.php?tid=622934)



Looping Through multi-dimensional array - Tass007 - 28.11.2016

Hey guys, I'm trying to use an array and go through specific values so that when I call the function the next value in the array gets SetPlayerSkin.

I don't know if that makes any sense. Basically I'm making a script that whenever called it gets the next value in the array and then sets the player's skin to the value. However I'm getting error's and I don't quite understand what I'm meant to do. I've read Vince's tutorial about Looping through arrays.

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

However whenever he does it he uses an enum and I'm not so when I'm using my array I don't know what value to put in as I keep getting
Код:
error 035: argument type mismatch (argument 2)
I hope this is making sense Here is my array:

PHP код:
static const FemaleSkins[78][] =
{
    {
9},{10},{11},{12},{13},{31},{39},{40},{41},{53},{54},{55},{56},{63},{64},{65},{69},{75},{76},{77},{85},{87},{88},{89},{90},{91},{93},{129},{130},{131},//30
    
{138},{129},{140},{141},{145},{148},{150},{151},{142},{157},{169},{172},{178},{190},{191},{192},{193},{194},{195},{196},{197},{198},{199},{201},//54
    
{205},{207},{214},{215},{216},{218},{219},{224},{225},{226},{231},{232},{233},{237},{238},{243},{244},{245},{246},{251},{256},{257},{263},{298}//78
}; 
These are the female skin ids.

Then here is where i'm calling it. I've removed everything apart from the loop for you guys just to look at the loop.

PHP код:
public PlusSkin(playerid)
{
    ......
        for(new 
isizeof(FemaleSkins[]); i++)
        {
            
SetPlayerSkin(playeridFemaleSkins[i]);
        }
        ....
    }
        .....
        return 
1;

So in summary I'm getting the error

Код:
error 035: argument type mismatch (argument 2)
On this line

PHP код:
SetPlayerSkin(playeridFemaleSkins[i]); 
As I'm new to arrays and I'm not quite sure how they work without an enum.


Re: Looping Through multi-dimensional array - Dayrion - 28.11.2016

Why you make a 2Dimensions array for one value each time ? Remove every {} between each ID and you will get no errors and by the way, it's should work.


Re: Looping Through multi-dimensional array - Alvitr - 28.11.2016

umm..

maybe here have reason
https://sampforum.blast.hk/showthread.php?tid=318212

PHP код:
static const FemaleSkins[] = 
//{
    
9,10,11,12,13,31,39,40,41,53,54,55,56,63,64,65,69,75,76,77,85,87,88,89,90,91,93,129,130,131,//30 
    
138,129,140,141,145,148,150,151,142,157,169,172,178,190,191,192,193,194,195,196,197,198,199,201,//54 
    
205,207,214,215,216,218,219,224,225,226,231,232,233,237,238,243,244,245,246,251,256,257,263,298//78 
};//}
for(new isizeof(FemaleSkins); i++) 

    
SetPlayerSkin(playeridFemaleSkins[i]); 




Re: Looping Through multi-dimensional array - Tass007 - 28.11.2016

Thanks guys. I didn't know what I was doing


Re: Looping Through multi-dimensional array - Dayrion - 28.11.2016

2D Array is usefull when you have more than one value for different 'position'.
Example:
PHP код:
static const Float:dmZone4Coord[3][4] = // dmzone desert
{
    {
277.8264,1956.293217.6406,267.2016}, // Spawn type1
    
{275.67131956.513317.6406266.3391}, //Spawn type2
    
{278.16631988.640717.6406270.3955//Spawn type3
}; 



Re: Looping Through multi-dimensional array - Tass007 - 28.11.2016

Right so because there's X and Y, it is a 2D Array? If it was X, Y and Z it'll be 3D? Or you'd use an enum?


Re: Looping Through multi-dimensional array - Micko123 - 28.11.2016

Check this out

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


Re: Looping Through multi-dimensional array - Tass007 - 28.11.2016

I've already read that. However it's sort of hard to follow as most of the picture's he's referring to aren't there.


Re: Looping Through multi-dimensional array - Micko123 - 28.11.2016

This??

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


Re: Looping Through multi-dimensional array - Tass007 - 28.11.2016

Yeah I've read that as well. I posted that topic in my initial post.