for - doesn't itter last array element - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: for - doesn't itter last array element (
/showthread.php?tid=172845)
for - doesn't itter last array element -
ziomal432 - 31.08.2010
I'm trying to do special loop, which iterates every array element. I've got this:
pawn Код:
new const Skins[] =
{
105, //0
106, //1
107, //2
102, //3
103, //4
104, //5
114, //6
115, //7
116, //8
108, //9
109, //10
110, //11
121, //12
122, //13
124, //14
126, //15
113 //16
};
for(new skin = Skins[0], skin_index = 1; skin_index < sizeof(Skins); skin = Skins[skin_index++])
printf("%d", skin);
print("Text"); //Debug
But doesn't iterate last array element:
Quote:
Originally Posted by console
[19:43:20] 105
[19:43:20] 106
[19:43:20] 107
[19:43:20] 102
[19:43:20] 103
[19:43:20] 104
[19:43:20] 114
[19:43:20] 115
[19:43:20] 116
[19:43:20] 108
[19:43:20] 109
[19:43:20] 110
[19:43:20] 121
[19:43:20] 122
[19:43:20] 124
[19:43:20] 126 //there's no 113 :/
[19:43:20] Text
|
Re: for - doesn't itter last array element -
Mauzen - 31.08.2010
try this: skin_index <= sizeof(Skins)
There might be some delay in the loop, so that it is ended when skin_index is too high (skin = Skins[skin_index++]) without running printf("%d", skin); again.
Re: for - doesn't itter last array element -
ziomal432 - 31.08.2010
I tried it, but debug string doesn't print :C
Re: for - doesn't itter last array element -
Mauzen - 31.08.2010
I doubt it, but maybe setting the size of the array may help.
new const Skins[17] =
Re: for - doesn't itter last array element -
ziomal432 - 31.08.2010
Still doesn't work
Re: for - doesn't itter last array element -
ziomal432 - 31.08.2010
This post -> Delete
Re: for - doesn't itter last array element -
Mauzen - 31.08.2010
For me it works with the <=
for(new skin = Skins[0], skin_index = 1; skin_index <= sizeof(Skins); skin = Skins[skin_index++])
EDIT: Oops, it does not work, forgot the debug message
This is not as comfortable as yours, but at least works:
for(new skin_index = 1; skin_index < sizeof(Skins); skin_index ++ )
printf("%d", Skins[skin_index]);