AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Send data to menu? (https://forums.alliedmods.net/showthread.php?t=87778)

Spunky 03-16-2009 09:07

Send data to menu?
 
Is there an easy way? Or a way at all? :/

SnoW 03-16-2009 09:33

Re: Send data to menu?
 
To menu... Are you meaning to the menu handler function or what?

Spunky 03-16-2009 09:34

Re: Send data to menu?
 
Yeah, what else would I mean? :P

SnoW 03-16-2009 12:08

Re: Send data to menu?
 
Quote:

Originally Posted by Spunky (Post 781818)
Yeah, what else would I mean? :P

Who knows? :grrr:
But aye. There's no way, since it can't be passed in menu_display. So... Probably you'll use global variable.

Emp` 03-16-2009 14:05

Re: Send data to menu?
 
If you are using the new menu system you can do it.
Put data as the third parameter in menu_additem

Then you can retrieve the data in the menu_handler like:
Code:

    //now lets create some variables that will give us information about the menu and the item that was pressed/chosen
    new data[6], iName[64]
    new access, callback
    //heres the function that will give us that information (since it doesnt magicaly appear)
    menu_item_getinfo(menu, item, access, data,5, iName, 63, callback)


SnoW 03-16-2009 14:13

Re: Send data to menu?
 
Aye, but if you need to use the infos for regonizing the items in the handler, it isn't possible to get what part in the string is the item's info and what that one, if you would add them both.

Emp` 03-16-2009 14:15

Re: Send data to menu?
 
Could simply make the data[] = "01otherdata"
all the way to "99otherdata"

str_to_num will still get the number correctly. Then you can just do data[2] to get the other data.

Edit: Even if you didn't want to use exactly that, you could seperate the data by an identifier.
formatex(data, len, "%d|%s", num, extra_data);

Then use strtok(data, Left, 20, Right, 20, '|');
And use str_to_num(Left) and then you have the extra data in Right

SnoW 03-16-2009 14:21

Re: Send data to menu?
 
Quote:

Originally Posted by Emp` (Post 782030)
...seperate the data by an identifier...

Didn't thinking using only numbers, but identifier's right, didn't think about it. Still this will soon sound like it's easier to only use the global variable.

Spunky 03-16-2009 16:21

Re: Send data to menu?
 
Seems like way too much trouble. Besides, I thought of just using a global variable right after posting here. Still, interesting to know that you can do it.

Exolent[jNr] 03-16-2009 17:09

Re: Send data to menu?
 
Actually, you can use the data originally like Emp` said without identifiers.
The "item" parameter in the handling function shows the item number that you did.

Code:
public menu_handler(id, menu, item) {     if( item == MENU_EXIT ) return;         new key = (item % 7) + 1;     new page = (item / 7) + 1;         // key = 1-7     // page = 1-(total pages) }


All times are GMT -4. The time now is 08:58.

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