Raised This Month: $ Target: $400
 0% 

need help with menu strings


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
reinert
Veteran Member
Join Date: Feb 2007
Old 01-06-2011 , 10:32   need help with menu strings
Reply With Quote #1

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)
reinert is offline
Elusive138
Senior Member
Join Date: Dec 2010
Old 01-06-2011 , 11:17   Re: need help with menu strings
Reply With Quote #2

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.
Elusive138 is offline
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 01-06-2011 , 15:24   Re: need help with menu strings
Reply With Quote #3

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 }
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
Elusive138
Senior Member
Join Date: Dec 2010
Old 01-06-2011 , 15:54   Re: need help with menu strings
Reply With Quote #4

Quote:
Originally Posted by wrecked_ View Post
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)
Elusive138 is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 01-06-2011 , 15:59   Re: need help with menu strings
Reply With Quote #5

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.

Last edited by SnoW; 01-06-2011 at 16:02.
SnoW is offline
Send a message via MSN to SnoW
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-06-2011 , 18:18   Re: need help with menu strings
Reply With Quote #6

Quote:
Originally Posted by Elusive138 View Post
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.
__________________

Last edited by fysiks; 01-06-2011 at 19:08.
fysiks is offline
Elusive138
Senior Member
Join Date: Dec 2010
Old 01-06-2011 , 18:37   Re: need help with menu strings
Reply With Quote #7

Quote:
Originally Posted by fysiks View Post
data is limited to 5 string characters (6 cells) by the "New Menu" system BTW.
Really? Wow.. whoops? :S
Elusive138 is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 01-06-2011 , 18:59   Re: need help with menu strings
Reply With Quote #8

Quote:
Originally Posted by fysiks View Post
data is limited to 5 string characters (6 cells) by the "New Menu" system BTW.
When did that happen?
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-06-2011 , 19:00   Re: need help with menu strings
Reply With Quote #9

Quote:
Originally Posted by Emp` View Post
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.
__________________

Last edited by fysiks; 01-06-2011 at 19:07.
fysiks is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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