Raised This Month: $51 Target: $400
 12% 

Solved [ H3LP ] Macro


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 12-29-2017 , 10:40   [ H3LP ] Macro
Reply With Quote #1

Hello, what's wrong with this macro?

Code:
#define CHECK_ISPLAYER(%1)  if (!(1 <= %1 <= get_maxplayers())) { log_error(AMX_ERR_NATIVE, "[ZP] Invalid player index %d", %1); return 0; }
__________________









Last edited by CrazY.; 12-30-2017 at 16:15.
CrazY. is offline
DjSoftero
Veteran Member
Join Date: Nov 2014
Location: Lithuania
Old 12-29-2017 , 11:20   Re: [ H3LP ] Macro
Reply With Quote #2

what exactly isn`t working? I think you have to add "(" before if statement and at the end of the line. But I could be wrong, because I don`t use macros at all.
PHP Code:
#define CHECK_ISPLAYER(%1)  ( if (!(1 <= %1 <= get_maxplayers())) { log_error(AMX_ERR_NATIVE, "[ZP] Invalid player index %d", %1); return 0; } ) 
or perhaps you can`t use an if statement...
PHP Code:
#define CHECK_ISPLAYER(%1)  ( (!(1 <= %1 <= get_maxplayers())) ? (log_error(AMX_ERR_NATIVE, "[ZP] Invalid player index %d", %1); return 0; ) : (return 1;) ) 
__________________
retired chump

Last edited by DjSoftero; 12-29-2017 at 11:22.
DjSoftero is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-29-2017 , 11:23   Re: [ H3LP ] Macro
Reply With Quote #3

PHP Code:
#define CHECK_ISPLAYER(%1)  \
{ \
    if(!(
<= %<= get_maxplayers())) \
    { \
        
log_error(AMX_ERR_NATIVE"[ZP] Invalid player index %d", %1); \
        return 
0; \
    } \

__________________
HamletEagle is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 12-29-2017 , 12:05   Re: [ H3LP ] Macro
Reply With Quote #4

Quote:
Originally Posted by DjSoftero View Post
what exactly isn`t working?
Warning 217.

Quote:
Originally Posted by HamletEagle View Post
PHP Code:
#define CHECK_ISPLAYER(%1)  \
{ \
    if(!(
<= %<= get_maxplayers())) \
    { \
        
log_error(AMX_ERR_NATIVE"[ZP] Invalid player index %d", %1); \
        return 
0; \
    } \

Thanks.
__________________








CrazY. is offline
DjSoftero
Veteran Member
Join Date: Nov 2014
Location: Lithuania
Old 12-29-2017 , 12:25   Re: [ H3LP ] Macro
Reply With Quote #5

i didnt get any warning using this version of compiler: AMX Mod X Compiler 1.8.3-dev+5143
__________________
retired chump
DjSoftero is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 12-29-2017 , 12:27   Re: [ H3LP ] Macro
Reply With Quote #6

Really? Hmm, that's weird, because I'm using the same version...
__________________








CrazY. is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 12-29-2017 , 22:06   Re: [ H3LP ] Macro
Reply With Quote #7

I reopened the thread because I am still getting warning 217 and error 036.
__________________








CrazY. is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 12-29-2017 , 22:17   Re: [ H3LP ] Macro
Reply With Quote #8

Quote:
Originally Posted by CrazY. View Post
I reopened the thread because I am still getting warning 217 and error 036.
Error code doesn't help much. Better just post compiler output.
__________________
klippy is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 12-30-2017 , 16:15   Re: [ H3LP ] Macro
Reply With Quote #9

I have already encountered the problem, it is probably a compiler bug. I can't add the semicolon at the end of the macro, otherwise I get the warning/error I quoted above.

EDIT: In fact, it was my own error, since it is not allowed to add semicolons at the end of a function, just after the bracket.
__________________









Last edited by CrazY.; 12-30-2017 at 16:18.
CrazY. is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 01-06-2018 , 22:40   Re: [ H3LP ] Macro
Reply With Quote #10

Quote:
Originally Posted by HamletEagle View Post
PHP Code:
#define CHECK_ISPLAYER(%1)  \
{ \
    if(!(
<= %<= get_maxplayers())) \
    { \
        
log_error(AMX_ERR_NATIVE"[ZP] Invalid player index %d", %1); \
        return 
0; \
    } \

Code:
#define CHECK_ISPLAYER(%1)  \ do { \     if (!(1 <= %1 <= get_maxplayers())) \     { \         log_error(AMX_ERR_NATIVE, "[ZP] Invalid player index %d", %1); \         return 0; \     } else { \         break; \     } \ } while (register_plugin("", "", ""))
Now semicolon can be used.
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
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 12:41.


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