Array must be indexed error
#1

i get a weird error if someone will help me he will get reped +1

here is my code
pawn Код:
public ServerOneSecondVariables()
{
    //City Hall robbed recently
    if(CityHallWasRobbedRecently >= 1)
    {
       CityHallWasRobbedRecently --;
    }
    return 1;
}

here is my error
pawn Код:
C:\Users\TOSHIBANET\Documents\Photoshop Documents\TeamDeathMatch\gamemodes\CNR.pwn(3279) : error 033: array must be indexed (variable "CityHallWasRobbedRecently")
C:\Users\TOSHIBANET\Documents\Photoshop Documents\TeamDeathMatch\gamemodes\CNR.pwn(3281) : error 022: must be lvalue (non-constant)
C:\Users\TOSHIBANET\Documents\Photoshop Documents\TeamDeathMatch\gamemodes\CNR.pwn(3281) : warning 215: expression has no effect
Reply
#2

Then you probably declared it as:

Код:
new CityHallWasRobbedRecently [];
just change it to:
Код:
new CityHallWasRobbedRecently ;
IF.. you're only using one CityHall off-course, else you need to give the index of the cityhall
between those brackets like:
Код:
new CityHallWasRobbedRecently [0];
for if the First city hall has been robbed, then change the 0 to a 1 for the second etc etc.

Hope this helped.
Reply
#3

You dont have to give index, but in that case script will use more memory, but youll need to use index while calling that var
pawn Код:
new CityHallWasRobbedRecently[];

CityHallWasRobbedRecently[0]--;
And as VenomXNL said, first index starts with 0 not with 1, so if you have e.g 15 cityhalls, to change first one youll use index 0, to change 5th one Youll use index 4 etc...
Reply
#4

Never mind i figured it out
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)