AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   need help with menu strings (https://forums.alliedmods.net/showthread.php?t=147194)

reinert 01-06-2011 10:32

need help with menu strings
 
PHP Code:

    menu_additem(CC_menu"\wSweden""Sweden");
    
menu_additem(CC_menu"\wFinland""Finland"); 


I would like to get the name of chosen country in my handler ...

PHP Code:

    new data[6], iName[64];
    new 
_accesscallback;
    
    
menu_item_getinfo(CC_menuitem_accessdatacharsmax(data), iName63callback);
    new 
iCountry str_to_num(data);
    
    switch( 
iCountry )
    {
        default:
        {
        
copy(iSelectedCountry[id], 32iCountry);
        
client_print(idprint_chat"selected country %s"iSelectedCountry[id])
        }
    }
    
menu_destroy(CC_menu);
    return 
PLUGIN_HANDLED;


What is wrong it gives me error:

Error: Argument type mismatch (argument 3)

Elusive138 01-06-2011 11:17

Re: need help with menu strings
 
1. Make your data array bigger
PHP Code:

new data[6

==>
PHP Code:

new data[64

2. Take this line out
PHP Code:

new iCountry str_to_num(data); 

3. Take out the switch.
4. Replace all occurrences of iCountry with data

You were trying to turn the country name string into a number (integer), and then copy that integer into a string...

btw, you should rename iSelectedCountry to szSelectedCountry, though it isn't necessary.

wrecked_ 01-06-2011 15:24

Re: need help with menu strings
 
The above post is unnecessary.

It surprises me how little people think about the things they are typing, and just copy the way others get things done. You name one of your variables iName and it doesn't occur to you that maybe that's the name of the option?

Code:
Foo() {     new menu = menu_create( "Countries", "Handler" )     menu_additem( menu, "Sweden", "1", 0 )         // other items, display... } public Handler( id, menu, item ) {     new ChoiceName[32]     new access     new callback     menu_item_getinfo( menu, item, access, _, _, ChoiceName, 31, callback )     // ChoiceName = "Sweden" if the client chose that option }

Elusive138 01-06-2011 15:54

Re: need help with menu strings
 
Quote:

Originally Posted by wrecked_ (Post 1387588)
The above post is unnecessary.

It surprises me how little people think about the things they are typing, and just copy the way others get things done. You name one of your variables iName and it doesn't occur to you that maybe that's the name of the option?

Code:
Foo() { new menu = menu_create( "Countries", "Handler" ) menu_additem( menu, "Sweden", "1", 0 ) // other items, display... } public Handler( id, menu, item ) { new ChoiceName[32] new access new callback

menu_item_getinfo( menu, item, access, _, _, ChoiceName, 31, callback ) // ChoiceName = "Sweden" if the client chose that option }


If he really wants to colour or otherwise format his menu options that could get a bit annoying (unless the formatting is uniform, in which case it would be easy enough to start reading at iName[2] or whatever)

SnoW 01-06-2011 15:59

Re: need help with menu strings
 
What you should do in the first place is making the country names properly to a global array, like that creating the menu is much cleaner in a loop ( Even you didn't have more than two countries which I doubt ). After we've followed good habits it's easy to get the name with the item index in the handler so that no menu_item_getinfo is needed. All the benefits of using indexes for countries included.

fysiks 01-06-2011 18:18

Re: need help with menu strings
 
Quote:

Originally Posted by Elusive138 (Post 1387409)
1. Make your data array bigger
PHP Code:

new data[6

==>
PHP Code:

new data[64

2. Take this line out
PHP Code:

new iCountry str_to_num(data); 


data is limited to 5 string characters (6 cells) by the "New Menu" system BTW.

I was mistaken. My testing didn't work correctly.

Elusive138 01-06-2011 18:37

Re: need help with menu strings
 
Quote:

Originally Posted by fysiks (Post 1387753)
data is limited to 5 string characters (6 cells) by the "New Menu" system BTW.

Really? Wow.. whoops? :S

Emp` 01-06-2011 18:59

Re: need help with menu strings
 
Quote:

Originally Posted by fysiks (Post 1387753)
data is limited to 5 string characters (6 cells) by the "New Menu" system BTW.

When did that happen?

fysiks 01-06-2011 19:00

Re: need help with menu strings
 
Quote:

Originally Posted by Emp` (Post 1387773)
When did that happen?

When I tested it. I tried more but it didn't do anymore than 5. Maybe I did something wrong. Is there a limit then?

EDIT: I was wrong, I must not have gotten the correct .amxx when I was trying to test it.


All times are GMT -4. The time now is 02:07.

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