SA-MP Forums Archive
Index returning crazy high value - 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: Index returning crazy high value (/showthread.php?tid=597104)



Index returning crazy high value - Alex_T - 26.12.2015

So I have a problem, I is returning as 2515036 for some reason.




Код:
	for(new i=0;i<10;i++) 
	{
			format(query, sizeof(query), "%s, `factionWeapon%d` = '%d', `factionAmmo%d` = '%d'", query, i, FactionData[factionid][factionWeapons][i], i, FactionData[factionid][factionAmmo][i]);
	}
Код:
[debug] Run time error 4: "Array index out of bounds"
[debug]  Accessing element at index 2515036 past array upper bound 10
[debug] AMX backtrace:
[debug] #0 0005af34 in Faction_Save (factionid=0) at lsr.pwn:4913
[debug] #1 00058f8c in public cmd_savefaction (playerid=0, params[]=@003009bc "") at lsr.pwn:4777
[debug] #2 native CallLocalFunction () from samp-server.exe
[debug] #3 00000854 in public OnPlayerCommandText (playerid=0, cmdtext[]=@00300988 "/savefaction") at C:\Program Files (x86)\PAWN Compiler\include\zcmd.inc:104



Re: Index returning crazy high value - prineside - 26.12.2015

Add printf( "%i", i ); before format and run again to see how it changes on each iteration.
Looks like your code is correct, so I can just guess what's wrong


Re: Index returning crazy high value - Alex_T - 26.12.2015

So I added this code and got this value: Change: 3163864

Код:
printf("Change: %i", i);



Re: Index returning crazy high value - prineside - 26.12.2015

It prints just one time? Is there anything before this message?


Re: Index returning crazy high value - Alex_T - 26.12.2015

Nothing before this message. Only prints once

It looks like this

Код:
for(new i=0;i<10;i++) 
	{
			printf("Change: %i", i);
			format(query, sizeof(query), "%s, `factionWeapon%d` = '%d', `factionAmmo%d` = '%d'", query, i, FactionData[factionid][factionWeapons][i], i, FactionData[factionid][factionAmmo][i]);
	}



Re: Index returning crazy high value - Alex_T - 27.12.2015

BUMP


Re: Index returning crazy high value - SickAttack - 27.12.2015

I just find it ironic to help you, you don't even give out a simple "thank you" after you get a solution to one of your couple of dozens of problems.


Re: Index returning crazy high value - Mauzen - 27.12.2015

Thats an uncommon problem. Are you using any extraordinary plugins or includes?
Also post the whole function (Faction_Save)


Re: Index returning crazy high value - Alex_T - 27.12.2015

Код:
Faction_Save(factionid)
{
	static
	    query[2048];

	format(query, sizeof(query), "UPDATE `factions` SET `factionName` = '%s', `factionColor` = '%d', `factionType` = '%d', `factionRanks` = '%d', `factionLockerX` = '%f', `factionLockerY` = '%f', `factionLockerZ` = '%f', `factionLockerAngle` = '%f', `factionLockerInt` = '%d', `factionLockerWorld` = '%d', `SpawnX` = '%f', `SpawnY` = '%f', `SpawnZ` = '%f', `SpawnInterior` = '%d', `SpawnVW` = '%d'",
		mysql_real_escape_string(FactionData[factionid][factionName]),
		FactionData[factionid][factionColor],
		FactionData[factionid][factionType],
		FactionData[factionid][factionRanks],
		FactionData[factionid][factionLockerPos][0],
		FactionData[factionid][factionLockerPos][1],
		FactionData[factionid][factionLockerPos][2],
		FactionData[factionid][factionLockerPos][3],
		FactionData[factionid][factionLockerInt],
		FactionData[factionid][factionLockerWorld],
		FactionData[factionid][SpawnX],
		FactionData[factionid][SpawnY],
		FactionData[factionid][SpawnZ],
		FactionData[factionid][SpawnInterior],
		FactionData[factionid][SpawnVW]);
	for(new i=0;i<10;i++) 
	{
		printf("Change: %i", i);
		format(query, sizeof(query), "%s, `factionWeapon%d` = '%d', `factionAmmo%d` = '%d'", query, i, FactionData[factionid][factionWeapons][i], i, FactionData[factionid][factionAmmo][i]);
	}
	format(query, sizeof(query), "%s WHERE `factionID` = '%d'",
		query,
		FactionData[factionid][factionID]
	);
	return mysql_tquery(MySQLCon, query);
}



Re: Index returning crazy high value - Alex_T - 27.12.2015

BUMP Need this to be fixed