Raised This Month: $32 Target: $400
 8% 

TopMenu with Transitional Syntax


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 06-16-2018 , 19:12   TopMenu with Transitional Syntax
Reply With Quote #1

I'm getting tag mismatch warning when trying to compile.

PHP Code:
(561) : warning 213tag mismatch 
This is line 561:

PHP Code:
hAdminMenu topmenu
Here is the code function causing the warning.

PHP Code:

/* TopMenu Handle */
TopMenu hAdminMenu null;

public 
void OnAdminMenuReady(Handle topmenu)
{
    if (
topmenu == hAdminMenu)
    {
        return;
    }

    
hAdminMenu topmenu;

I understand that Handle and TopMenu tags are the reason for this, but what would be a fix?
__________________
Spirit_12 is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 06-16-2018 , 22:19   Re: TopMenu with Transitional Syntax
Reply With Quote #2

You'll have to view_as<TopMenu>(topmenu).
Fyren is offline
LenHard
Senior Member
Join Date: Jan 2016
Old 06-17-2018 , 02:38   Re: TopMenu with Transitional Syntax
Reply With Quote #3

PHP Code:
public void OnAdminMenuReady(Handle hMenu)
{
    
TopMenu hTopMenu TopMenu.FromHandle(hMenu);

    if (
hTopMenu != hAdminMenu)
    {
        
hAdminMenu hTopMenu;
        
        
// Your code...
    
}

Try this
__________________
LenHard is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 06-17-2018 , 19:58   Re: TopMenu with Transitional Syntax
Reply With Quote #4

Quote:
Originally Posted by Fyren View Post
You'll have to view_as<TopMenu>(topmenu).
You mean like this? It solved the warning, but just for clarification.

PHP Code:
hAdminMenu view_as<TopMenu>(topmenu); 
__________________
Spirit_12 is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 06-17-2018 , 22:41   Re: TopMenu with Transitional Syntax
Reply With Quote #5

Yes.

The difference between doing view_as and FromHandle that LenHard mentioned is the latter will cause a runtime error if the handle isn't actually a TopMenu.
Fyren is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-18-2018 , 09:39   Re: TopMenu with Transitional Syntax
Reply With Quote #6

Actually, there is one good question here:

Why has adminmenu.inc not been updated to use more specific handle types for its methods and forwards?
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 06-18-2018 , 09:53   Re: TopMenu with Transitional Syntax
Reply With Quote #7

Changing the signature of the forward would break existing code.
Fyren is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-18-2018 , 11:48   Re: TopMenu with Transitional Syntax
Reply With Quote #8

Quote:
Originally Posted by Fyren View Post
Changing the signature of the forward would break existing code.
At the risk of sounding hostile, that sounds like something that should have been addressed when transitional syntax was added. Private forwards can bypass this using typesets, but global forwards are now forever stuck using just Handle.

Also, that doesn't address why things like AddTargetsToMenu still takes a Handle rather than a Menu.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
ThatKidWhoGames
Veteran Member
Join Date: Jun 2013
Location: IsValidClient()
Old 06-18-2018 , 13:23   Re: TopMenu with Transitional Syntax
Reply With Quote #9

Quote:
Originally Posted by Powerlord View Post
At the risk of sounding hostile, that sounds like something that should have been addressed when transitional syntax was added. Private forwards can bypass this using typesets, but global forwards are now forever stuck using just Handle.

Also, that doesn't address why things like AddTargetsToMenu still takes a Handle rather than a Menu.
+1
ThatKidWhoGames is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 06-18-2018 , 15:12   Re: TopMenu with Transitional Syntax
Reply With Quote #10

Transitional syntax is transitional because it does not attempt to solve all problems. It was meant to leave the majority of existing code as it was while providing some new conveniences. New warnings since 1.7 have generally only for things likely to be removed in a theoretical future version that majorly breaks compatibility, besides the new features.

AddTargetsToMenu would have been added to a methodmap, but it's implemented in the adminmenu plugin away from the rest of topmenu and an adminmenu methodmap doesn't seem particularly useful.
Fyren 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 19:17.


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