AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   error 033: array must be indexed (https://forums.alliedmods.net/showthread.php?t=93214)

moosewanted 05-25-2009 19:39

error 033: array must be indexed
 
An extract from a plugin I'm making.
I guess what the error means is that the array used in teleother_confirm_menu = menu_create(teleother_confirm_menu_name[id],"teleother_confirm_menu_handle") must be constant but im using a variable

I tried to fix it by formatting a string with the id already in it but it doesn't work.

PHP Code:

new teleother_confirm_menu[33]
new 
teleother_confirm_menu_name[33][58]


public 
teleother(idtargetid)
{
    new 
Arg1[32]
    
read_argv(1Arg131)
    new 
targetplayer cmd_target(idArg14)
    
    if(!
targetplayer)
    {
        
client_print(idprint_chat"%s Sorry, player %s could not be found or targetted!"PLUGIN_SNAMEArg1)
        return 
PLUGIN_HANDLED
    
}
    else
    {
        new 
username[32]
        
get_user_name(targetplayerusername31)

        
format(teleother_confirm_menu_name[id], 57"%s would like you to join them"username)
        new 
menu_name[32]
        
format(menu_name31"teleother_confirm_menu_name[%i]"id)
        new 
menu_id[27]
        
format(menu_id26"teleother_confirm_menu[%i]"id)
        
teleother_confirm_menu menu_create(menu_name,"teleother_confirm_menu_handle")
        
menu_additem(menu_id"yes"id)
        
menu_additem(menu_id"no"id)

        
menu_display(targetplayermenu_id0)
    }


I can't really think at the moment, perhaps I am to tired but I would appreciate some help.
Thanks.

EDIT:

Other problem. The reason I have used arrays for a menu is because I couldn't think of any other way.
What I thought:
The menu is specific to a single player, so it can't be global/constant because then it wouldn't be specific as each player would see the same menu?

Solution, have many different menu's?

EDIT2: This code is so baad >.<

Starsailor 05-25-2009 20:26

Re: error 033: array must be indexed
 
That code is so bad

Bugsy 05-25-2009 21:08

Re: error 033: array must be indexed
 
Try this chief:

PHP Code:

teleother_confirm_menu menu_create(menu_name,"teleother_confirm_menu_handle"

should be

PHP Code:

teleother_confirm_menu[id] = menu_create(menu_name,"teleother_confirm_menu_handle"


moosewanted 05-25-2009 21:19

Re: error 033: array must be indexed
 
Yeh, I should have worked that out from the compiler error. Thanks. Also, how would I pass a variable in:

menu_additem(menu_id, "no", id)

as id errors to:
error 035: argument type mismatch (argument 3)

fysiks 05-25-2009 23:30

Re: error 033: array must be indexed
 
Quote:

Originally Posted by moosewanted (Post 834790)
Yeh, I should have worked that out from the compiler error. Thanks. Also, how would I pass a variable in:

menu_additem(menu_id, "no", id)

as id errors to:
error 035: argument type mismatch (argument 3)

The third argument must be a string (link).

You can parse multiple data into the third argument and then extract it later. That is only one suggestion, there might be better ways.


All times are GMT -4. The time now is 01:35.

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