AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Error: Array must be indexed (https://forums.alliedmods.net/showthread.php?t=74728)

skis 07-23-2008 19:34

Error: Array must be indexed
 
Can someone please look at this code and see if you can see anything wrong? I get this error:

Error: Array must be indexed (variable "-unknown-") on line 31

Code:

22 public bombpickup() {
23    new players[32];
24    new num, i;
25    get_players(players, num, "e", "TERRORIST");
26    for(i = 0;i < num; i++) {
27        new weapons[32];
28        new numweapons, j;
29        get_user_weapons(i, weapons, numweapons);
30        for (j = 0; j < numweapons; j++) {
31            if (weapons[j] == "weapon_c4") {
32                //do something if he has the bomb
33            }
34        }
35    }
36 }

Does the variable "j" not work as an index in a for loop or something?

Jon 07-23-2008 19:56

Re: Error: Array must be indexed
 
You can't compare strings that way. Use:
Code:

if(equal(weapons[j], "weapon_c4"))

skis 07-23-2008 20:21

Re: Error: Array must be indexed
 
Thanks


All times are GMT -4. The time now is 05:40.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.