SA-MP Forums Archive
Foreach bug? - 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: Foreach bug? (/showthread.php?tid=455613)



Foreach bug? - RCON1 - 02.08.2013

Hi, it's my first thread at this forum, so - regards.

Now I'm turn to my issue: I've some backtraces in console (I'm check that with crashdetect):

Код:
[05:40:14] wyzuc 1
[05:40:14] wyzuc 2 0 0
[05:40:14] wyzuc 2 0 0
[05:40:14] [debug] Run time error 4: "Array index out of bounds"
[05:40:14] [debug]   Accessing element at index 53 past array upper bound 52
[05:40:14] [debug] AMX backtrace:
[05:40:14] [debug] #0  0007a988 in public script_hy_update () at ./current/libs/event/events/main.inc:1907
[05:40:15] początek
[05:40:15] po spawn
Line 1907 is:
Код:
new Float:position_[6];
		foreach (new ply : h_y_players) //1907
function, which update HAY:


Код:
forward script_hy_update( );
public script_hy_update( )
{
	if( script_hy[ statees ] != true ) return 1;
	
	if( Iter_Count( h_y_players) == 0 )
	{
		script_destory_hy_v();
		KillTimer( script_hy[ Timer ] );
		Iter_Clear( h_y_players);
		script_hy[ statees ] = false;
		sendClientMessageToAll( COLOR_ERROR, "Hay zostało zakończone z powodu braku graczy." );
		return 1;
	}
	event_saved();
	
	if( Iter_Count( h_y_players) == 1 ) //tutaaj jesli jest jeden
	{
		 
		KillTimer( script_hy[ Timer ] );
		new p = Iter_First(h_y_players);
		if( IsPlayerConnected( p ) )
		{
			printf("początek");
			Iter_Remove( h_y_players, p );
			SetPlayerVirtualWorld( p, 0 );
			TogglePlayerControllable( p, 1 );
			SetPlayerHealth( p, 100.0 );
			ResetPlayerWeapons( p );
			
			SpawnPlayer( p );
			printf("po spawn");
			new kasy = random( 10000 ), score = random(100);
			format( ee_stri, sizeof( ee_stri ), "Gracz %s (%d) po raz %d wygrał {b}/HY{/b}. I otrzymuje {b}%d Score i %d${/b} ", playerNick( p ), p, addPointEvent( p, stats_hy ), score, kasy );
			sendClientMessageToAll( COLOR_ORANGE, ee_stri );
			//break;
		}
		script_destory_hy_v();
		Iter_Clear( h_y_players);
		script_hy[ statees ] = false;
		return 1;
	}
	
	if( script_hy[ winreed ] != INVALID_PLAYER_ID )
	{
		
		KillTimer( script_hy[ Timer ] );
		GivePlayerMoney( script_hy[ winreed ], 10000 );
		
		new kasy = random( 10000 ), score = random(100);
		format( ee_stri, sizeof( ee_stri ), "Gracz %s (%d) po raz %d wygrał {b}/HY{/b}. I otrzymuje {b}%d Score i %d${/b} ", playerNick( script_hy[ winreed ] ), script_hy[ winreed ], addPointEvent( script_hy[ winreed ], stats_hy ), score, kasy );
		
		sendClientMessageToAll( COLOR_ORANGE, ee_stri );
		script_destory_hy_v();
		script_hy[ statees ] = false;
		Iter_Clear( h_y_players);
		return 1;
	}
	if( Iter_Count( h_y_players) > 1 ){
		new Float:position_[6];
		foreach (new ply : h_y_players)
		{
			
			GetPlayerPos( ply, position_[ 0 ], position_[ 1 ], position_[ 2 ] );
			if( position_[ 2 ] < 110.0 ){
				if( Iter_Contains( h_y_players, ply ) ){
					Iter_Remove( h_y_players, ply );
					printf("wyzuc 1");
				}
				SpawnPlayer( ply );
				printf("wyzuc 2 0 0");
				continue;
			}
			if( IsPlayerInAnyVehicle(ply) )
			{
				if( Iter_Contains( h_y_players, ply ) ) {
					Iter_Remove( h_y_players, ply );
					printf("wyzuc 11");
				}
				SpawnPlayer( ply );
				printf("wyzuc 22");
			}
			
		}
	}
	event_saved();
	return 1;
}



Re: Foreach bug? - RCON1 - 02.08.2013

Sorry for double post.
I think I found (?) Foreach serious bug.
Код:
#include a_samp
#include foreach

new Iterator:test<100>;
public OnFilterScriptInit(){

	Iter_Add(test,5);
	Iter_Add(test,0);
	Iter_Add(test,1);
	Iter_Add(test,2);
	
	foreach( new i : test){
		if( i != 99 ){
			Iter_Remove(test,i);
		}
	}
	return 1;
}
Код:
loadfs x



 =======================================
 |                                     |
 |        YSI version 3.09.0684        |
 |        By Alex "******" Cole        |
 |                                     |
 =======================================

[debug] Run time error 4: "Array index out of bounds"
[debug]  Accessing element at index 101 past array upper bound 100
[debug] AMX backtrace:
[debug] #0 0000220c in public Itter_OnFilterScriptInit () at x.pwn:12
[debug] #1 0000142c in public ScriptInit_OnFilterScriptInit () at D:\GTA\serwerm
ap\include\include\YSI\y_iterate.inc:745
[debug] #2 000000e4 in Debug_Print0 () at D:\GTA\serwermap\include\include\YSI\i
nternal\..\y_scriptinit.inc:132
  Filterscript 'x.amx' loaded.