Fastest way to reset Enum with loop not working
#1

Fastest way to reset Enum with loop not working

Hello,
I have very big Enum to store players data, his length about 100...

I used this code OnPlayerConnect:
Код:
for(new i; i<sizeof(PEnum); i++)
		{
			PInfo[playerid][i] = 0;
		}
But I got strange errors:
Quote:

X(1) : error 039: constant symbol has no size
X(3) : warning 213: tag mismatch

I know what the errors means but why the code isn't working?
Thanks for help!
Reply
#2

Show us the PInfo and PEnum codes (creation).
Reply
#3

Here the Enum:
Код:
enum PEnum {
		// Here some stuff...
	};
And the PInfo:
Код:
new
	PInfo[MAX_PLAYERS][PEnum];
Reply
#4

You have to use
Код:
for(new i; i<sizeof(PEnum); i++)
		{
			PInfo[playerid][Stuff Name] = 0;
		}
Or if you have array "stuff":
Код:
for(new i; i<sizeof(PInfo[][Stuff Name]); i++)
		{
			PInfo[playerid][Stuff Name][i] = 0;
		}
Reply
#5

The code you've written is incorrect, your looping through the size of the array in this case MAX_PLAYERS while specifying your iterator as the array index in the ENUM.

You need do something like this

PInfo[playerid][enumval1] = 0;
PInfo[playerid][enumval2] = 0;
PInfo[playerid][enumval3] = 0;
PInfo[playerid][enumval4] = 0;

There is no need for looping unless one of your ENUM values is an array it's self!
Reply
#6

Quote:
Originally Posted by IstuntmanI
Посмотреть сообщение
You have to use
Код:
for(new i; i<sizeof(PEnum); i++)
		{
			PInfo[playerid][Stuff Name] = 0;
		}
Or if you have array "stuff":
Код:
for(new i; i<sizeof(PInfo[][Stuff Name]); i++)
		{
			PInfo[playerid][Stuff Name][i] = 0;
		}
This isn't what I want to do,
Please see this thread:
https://sampforum.blast.hk/showthread.php?tid=367225
Reply
#7

or try this

pawn Код:
for(new i; PEnum:i < PEnum; i++)
{
            PInfo[playerid][PEnum:i] = 0;
}
Reply
#8

Quote:
Originally Posted by HuSs3n
Посмотреть сообщение
or try this

pawn Код:
for(new i; PEnum:i < PEnum; i++)
{
            PInfo[playerid][PEnum:i] = 0;
}
You are fucking Genius! Thanks!
Reply
#9

Quote:
Originally Posted by ******
Посмотреть сообщение
I would just do:

pawn Код:
new x[PEnum];
PInfo[playerid] = x;
I will give it a try, thanks!
Reply
#10

Quote:
Originally Posted by ******
Посмотреть сообщение
I would just do:

pawn Код:
new x[PEnum];
PInfo[playerid] = x;
That is actually pretty clever and makes sense I never really looked at it that way the simplest solution is the best solution when it is effective I think people tend to over think problems sometimes myself included.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)