SA-MP Forums Archive
I can use this? - 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: I can use this? (/showthread.php?tid=662349)



I can use this? - qRazor - 29.12.2018

Hello guys, i have one question. I can use foreach in another foreach? I will leave below an example..

Код HTML:
foreach(Helpers, helperid) {
     my code here
     bla bla
     foreach(NewbiesReports, playerid) {
          my code here
          bla bla
     }
}
* Helpers and NewbiesReports are iterators.


Re: I can use this? - Banditul18 - 29.12.2018

You can. Also that is antic foreach syntax


Re: I can use this? - qRazor - 29.12.2018

Quote:
Originally Posted by Banditul18
Посмотреть сообщение
You can. Also that is antic foreach syntax
And it will work fine? I don't want to appear problems.


Re: I can use this? - iorp - 29.12.2018

it will work fine, I had experience with this


Re: I can use this? - qRazor - 29.12.2018

Look, i make this:
Код HTML:
function OneSecTimer() {
	foreach(Helpers, h) {
		new playerid = HelperOccupied[h];
		foreach(NewbiesReports, p) {
			new helperid = NewbieOnHelper[p];
			if(strcmp(HelperOccupied[h], NewbieOnHelper[p], true) == 0) {
				NewbieCount[helperid]++;
				printf("[DEBUG]The countdown is on %d seconds.", NewbieCount[helperid]);
			}
			if(NewbieCount[helperid] == 60 && HelperDuty[helperid] == 1 && HelperOccupied[helperid] != -1 && HaveNewbie[playerid] == 1 && NewbieOnHelper[playerid] != -1) {
				SCM(helperid, -1, "{5CAD5C}Time to answer to question has expired. You will get another question if one is available.");
				NewbieCount[helperid] = 0;
				HelperOccupied[helperid] = -1;
				NewbieOnHelper[playerid] = -1;
				SearchHelperTimer[playerid] = SetTimerEx("SearchHelper", 30000, false, "i", playerid);
			}
		}
	}
	print("[DEBUG]Timer works with succesfully.");
	return 1;
}
But i have a problem... get all the debugs, it's okay. But after the timer - OneSecTimer no longer works(after he passed the 60 seconds - NewbieCount) why??


Re: I can use this? - XavMartin - 30.12.2018

Код HTML:
SetTimer("OneSecTimer", 1000, true);
Make sure that you are calling the timer every second. You can do that by setting the repeating parameter of the SetTimer function to true.


Re: I can use this? - qRazor - 30.12.2018

Quote:
Originally Posted by XavMartin
Посмотреть сообщение
Код HTML:
SetTimer("OneSecTimer", 1000, true);
Make sure that you are calling the timer every second. You can do that by setting the repeating parameter of the SetTimer function to true.
It is, the timer is in OnGameModeInit().

EDIT(1): I have an idea I will take each function and I'll test it.

EDIT(2): The problem is after these two functions, the timer stops:
Код HTML:
HelperOccupied[helperid] = -1;
NewbieOnHelper[playerid] = -1;
EDIT(3): I install crashdetect and i have some errors:
Код HTML:
[13:44:36] [DEBUG]The countdown is on 60 seconds.
[13:44:36] [DEBUG]Timer works with succesfully.
[13:44:37] [debug] Run time error 4: "Array index out of bounds"
[13:44:37] [debug]  Attempted to read/write array element at negative index -1
[13:44:37] [debug] AMX backtrace:
[13:44:37] [debug] #0 0000d9fc in public OneSecTimer () in nproject.amx
** Can anyone help me, please?


Re: I can use this? - qRazor - 30.12.2018

I resolve the problem. Thanks for trying to help me guys.