Problematic FOR function? - 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: Problematic FOR function? (
/showthread.php?tid=73665)
Problematic FOR function? -
NovaParadox - 16.04.2009
Can someone explain why when this code so much as touches the OnGameModeInit, whether it be in a called public function or in the OnGameModeInit itself, it does not execute anything afterwards?
Код:
for(new i; i < SERVER_LINKCOUNT + 1; i++)
{
new pickupid;
sLink[i][outsidex] = Link_Outside[i][0];
sLink[i][outsidey] = Link_Outside[i][1];
sLink[i][outsidez] = Link_Outside[i][2];
sLink[i][outsideid] = CreatePickup(1239,23,sLink[i][outsidex],sLink[i][outsidey],sLink[i][outsidez]);
pickupid = sLink[i][outsideid];
SERVER_LINKED_PICKUPS[pickupid] = i;
sLink[i][insidex] = Link_Inside[i][0];
sLink[i][insidey] = Link_Inside[i][1];
sLink[i][insidez] = Link_Inside[i][2];
sLink[i][insideid] = CreatePickup(1239,23,sLink[i][insidex],sLink[i][insidey],sLink[i][insidez]);
pickupid = sLink[i][insideid];
SERVER_LINKED_PICKUPS[pickupid] = i;
sLink[i][interior] = Link_Interior[i];
format(str, 128, "Link number %d created.",i);
print(str);
}
Re: Problematic FOR function? -
NovaParadox - 17.04.2009
Anybody, Does nobody know why it is doing thing? If it can't be worked around should I place it at the end of the OnGameModeInit?
Re: Problematic FOR function? -
Joe Staff - 17.04.2009
Unless it needs to be there, it doesn't matter. The problem is 'i' is eventually becoming a number larger than an indexed variable's size.
ex:
pawn Код:
new LOLVariable[50];
LOLVariable[60] = 0; //reacts as 'return 0'
Re: Problematic FOR function? -
NovaParadox - 17.04.2009
"i" has a set amount.
determined at the beginning of the script using:
"#define SERVER_LINKCOUNT 11"
it runs until it reaches 11 and then it stops, so that can't be the problem as the indexed variable is equal to the above define as well, they are always linked.
enum SERVER_LINK_ARRAY
{
Float

utsidex,
Float

utsidey,
Float

utsidez,
outsideid,
Float:insidex,
Float:insidey,
Float:insidez,
insideid,
interior
}
new sLink[SERVER_LINKCOUNT][SERVER_LINK_ARRAY];
EDIT: All I had to do was remove the +1 from the FOR command
Re: Problematic FOR function? -
Joe Staff - 17.04.2009
When an index is made it counts 0 as a variable.
e.g.
new Variable[50]
makes
Variable[0] through Variable[49]