Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Strange things in menus

  1. #1
    Private Lonsofore's Avatar
    Join Date
    Oct 2016
    Posts
    86
    Thanks
    82
    Thanked 38 Times in 25 Posts

    Strange things in menus

    It's again me. I'm making menu of weapons and I found a problem. This code works perfect:
    PHP Code:
    #ifndef DRAW_WEAPON_ITEM
    #define DRAW_WEAPON_ITEM(_key, _name) \
        
    itemDef \
        { \
            
    name            "button_" ## #_name \
            
    visible            1 \
            
    rect            ORIGIN_CHOICE ## _key 128 24 \
            
    forecolor        GLOBAL_UNFOCUSED_COLOR \
            
    dvar            "ui_weapon_" ## #_name \
            
    textfont        UI_FONT_NORMAL \
            
    textscale        .25 \
            
    textstyle        ITEM_TEXTSTYLE_SHADOWED \
            
    textalignx        10 \
            
    textaligny        20 \
            
    action \
            { \
                
    play "mouse_click"; \
                
    scriptMenuResponse "" ## #_name; \
            
    } \
            
    onFocus \
            { \
                
    play "mouse_over"; \
                
    show _name ## _info; \
                
    show weapon_propertiestext; \
            } \
        } 
    #endif
    DRAW_WEAPON_ITEM(Am1carbine_mp
    But this doesn't work:
    PHP Code:
    #ifndef DRAW_WEAPON_ITEM
    #define DRAW_WEAPON_ITEM(_key, _name) \
        
    itemDef \
        { \
            
    name            "button_" ## #_name \
            
    visible            1 \
            
    rect            ORIGIN_CHOICE ## _key 128 24 \
            
    forecolor        GLOBAL_UNFOCUSED_COLOR \
            
    dvar            "ui_weapon_" ## #_name \
            
    textfont        UI_FONT_NORMAL \
            
    textscale        .25 \
            
    textstyle        ITEM_TEXTSTYLE_SHADOWED \
            
    textalignx        10 \
            
    textaligny        20 \
            
    action \
            { \
                
    play "mouse_click"; \
                
    scriptMenuResponse "" ## #_name; \
            
    } \
            
    onFocus \
            { \
                
    play "mouse_over"; \
                
    show _name ## _info; \
                
    show weapon_propertiestext; \
            } \
        } 
    #endif

    #ifndef DRAW_WEAPON
    #define DRAW_WEAPON(_key, _name) \
        
    DRAW_WEAPON_ITEM(_key_name) \
    #endif

    DRAW_WEAPON(Am1carbine_mp
    Any ideas, why?

  2. #2
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,010
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    PHP Code:

    #ifndef DRAW_WEAPON 
    #define DRAW_WEAPON(_key, _name) \ 
        
    DRAW_WEAPON_ITEM(_key_name) \ 
    #endif 
    Last \ drags in the #endif and probably causes whatever kind of syntax error, which must be in your console somewhere (shift+tilde in menu)
    timescale 0.01

  3. The Following User Says Thank You to kung foo man For This Useful Post:

    kubislav23 (13th June 2017)

  4. #3
    Private Lonsofore's Avatar
    Join Date
    Oct 2016
    Posts
    86
    Thanks
    82
    Thanked 38 Times in 25 Posts
    Quote Originally Posted by kung foo man View Post
    PHP Code:

    #ifndef DRAW_WEAPON 
    #define DRAW_WEAPON(_key, _name) \ 
        
    DRAW_WEAPON_ITEM(_key_name) \ 
    #endif 
    Last \ drags in the #endif and probably causes whatever kind of syntax error, which must be in your console somewhere (shift+tilde in menu)
    Doesn't work with these both cases:
    PHP Code:
    #ifndef DRAW_WEAPON
    #define DRAW_WEAPON(_key, _name) \
        
    DRAW_WEAPON_ITEM(_key_name)
    #endif 
    PHP Code:
    #ifndef DRAW_WEAPON
    #define DRAW_WEAPON(_key, _name) DRAW_WEAPON_ITEM(_key, _name)
    #endif 
    Offtop: where are you? haven't seen you in IRC for a long time

  5. #4
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,010
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    Probably need to stringify right away then:

    Code:
    #define DRAW_WEAPON(_key, _name) DRAW_WEAPON_ITEM(#_key, #_name)
    timescale 0.01

  6. The Following User Says Thank You to kung foo man For This Useful Post:

    kubislav23 (13th June 2017)

  7. #5
    Private Lonsofore's Avatar
    Join Date
    Oct 2016
    Posts
    86
    Thanks
    82
    Thanked 38 Times in 25 Posts
    Quote Originally Posted by kung foo man View Post
    Probably need to stringify right away then:

    Code:
    #define DRAW_WEAPON(_key, _name) DRAW_WEAPON_ITEM(#_key, #_name)
    Doesn't work aswell

    Starting to think that we can't use variables in macroses in macroses, because this code works:
    PHP Code:
    #ifndef DRAW_LINES_MAIN
    #define DRAW_LINES_MAIN() \
        
    DRAW_LINE(102 1000 0 446 1COLOR_LINE_DARK) \
        
    DRAW_LINE(270 1010 0 1 268COLOR_LINE_DARK) \
    #endif 

  8. #6
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    I recogn this bug, but forgot the details

    but you actually can have variables in macros as kung did it here (DVAR_CHECK): https://killtube.org/showthread.php?...ull=1#post3524

  9. The Following User Says Thank You to serthy For This Useful Post:

    Lonsofore (14th June 2017)

  10. #7
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,010
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    I guess single values like 100 might be transferable through multiple macros, but stuff like 100 200 for colors e.g. fails (dunno what A in your example is). So just try to split the values into non-spaced strings, that might work. And/or post the error messages you get from the parser, should give some clues
    timescale 0.01

  11. The Following 2 Users Say Thank You to kung foo man For This Useful Post:

    kubislav23 (13th June 2017),Lonsofore (14th June 2017)

  12. #8
    Private Lonsofore's Avatar
    Join Date
    Oct 2016
    Posts
    86
    Thanks
    82
    Thanked 38 Times in 25 Posts
    Ok, I found that the problem with rect string - working nice without it. And here I found the main problem.

    This code works perfect:
    PHP Code:
    #ifndef DRAW_WEAPON_ITEM
    #define DRAW_WEAPON_ITEM(_key, _name) \
        
    itemDef \
        { \
            
    name            "button_" ## #_name \
            
    visible            1 \
            
    rect             _key 128 24 \
            
    forecolor        GLOBAL_UNFOCUSED_COLOR \
            
    dvar            "ui_weapon_" ## #_name \
            
    textfont        UI_FONT_NORMAL \
            
    textscale        .25 \
            
    textstyle        ITEM_TEXTSTYLE_SHADOWED \
            
    textalignx        10 \
            
    textaligny        20 \
        }
    #endif

    DRAW_WEAPON_ITEM(ORIGIN_CHOICEAm1carbine_mp
    And this code doesn't:
    PHP Code:
    #ifndef DRAW_WEAPON_ITEM
    #define DRAW_WEAPON_ITEM(_key, _name) \
        
    itemDef \
        { \
            
    name            "button_" ## #_name \
            
    visible            1 \
            
    rect             _key 128 24 \
            
    forecolor        GLOBAL_UNFOCUSED_COLOR \
            
    dvar            "ui_weapon_" ## #_name \
            
    textfont        UI_FONT_NORMAL \
            
    textscale        .25 \
            
    textstyle        ITEM_TEXTSTYLE_SHADOWED \
            
    textalignx        10 \
            
    textaligny        20 \
        }
    #endif

    #define DRAW_WEAPON(_key, _name)     DRAW_WEAPON_ITEM(_key, _name)

    DRAW_WEAPON(ORIGIN_CHOICEAm1carbine_mp
    But as we know (from old kung's message) we can use macroses with variables in macroses. So, I think, the problem with ORIGIN_CHOICEA. In second case something is wrong with it. And I guess that ORIGIN_CHOICEA in DRAW_WEAPON is setting to real variables. In first case we set just in DRAW_WEAPON_ITEM directly.

    Well, trying to find, how to fix it.
    Last edited by Lonsofore; 14th June 2017 at 11:53.

  13. #9
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Most rects in macros need a 5th and a 6th argument iirc.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  14. The Following User Says Thank You to IzNoGoD For This Useful Post:

    kung foo man (14th June 2017)

  15. #10
    Private Lonsofore's Avatar
    Join Date
    Oct 2016
    Posts
    86
    Thanks
    82
    Thanked 38 Times in 25 Posts
    Quote Originally Posted by IzNoGoD View Post
    Most rects in macros need a 5th and a 6th argument iirc.
    And you're right, it works. But I can't see the button with all these cases:
    PHP Code:
    rect     _key 128 24 HORIZONTAL_ALIGN_DEFAULT VERTICAL_ALIGN_DEFAULT
    PHP Code:
    rect     _key 128 24 HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN 
    PHP Code:
    rect     0 0  128 24 HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN \
    origin _key 
    Something strange with coordinates now
    Full code:
    PHP Code:
    #ifndef DRAW_WEAPON_ITEM
    #define DRAW_WEAPON_ITEM(_key, _name) \
        
    itemDef \
        { \
            
    name            "button_" ## #_name \
            
    visible            1 \
            
    rect             0 0  128 24 HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN \
            
    origin            _key \
            
    forecolor        GLOBAL_UNFOCUSED_COLOR \
            
    dvar            "ui_weapon_" ## #_name \
            
    textfont        UI_FONT_NORMAL \
            
    textscale        .25 \
            
    textstyle        ITEM_TEXTSTYLE_SHADOWED \
            
    textalignx        10 \
            
    textaligny        20 \
        }
    #endif

    #define DRAW_WEAPON(_key, _name)     DRAW_WEAPON_ITEM(_key, _name)

    DRAW_WEAPON(ORIGIN_CHOICEAm1carbine_mp

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •