Array must be indexed error - 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: Array must be indexed error (
/showthread.php?tid=477631)
Array must be indexed error -
DarkLored - 25.11.2013
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
Re: Array must be indexed error -
VenomXNL - 25.11.2013
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.
Re: Array must be indexed error -
CoaPsyFactor - 25.11.2013
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...
Re: Array must be indexed error -
DarkLored - 25.11.2013
Never mind i figured it out