I can use this?
#1

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.
Reply
#2

You can. Also that is antic foreach syntax
Reply
#3

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.
Reply
#4

it will work fine, I had experience with this
Reply
#5

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??
Reply
#6

Код 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.
Reply
#7

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?
Reply
#8

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


Forum Jump:


Users browsing this thread: 1 Guest(s)