SA-MP Forums Archive
Define. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Define. (/showthread.php?tid=552883)



Define. - JaKe Elite - 27.12.2014

Is there any possible way to use this on displaying stuffs such as "Enable" if true and "Disable" false (print)

pawn Код:
#define TEST true
Is there anyway to do it without using the functions manually but this.

pawn Код:
new yes[4] = "Yes", no[3] = "No";
printf("Test: %s", TEST ? yes : no);



Re: Define. - M4D - 27.12.2014

What do you mean ?
If TEST defined as true, server print Yes and if TEST defined False server print No ?


Re: Define. - JaKe Elite - 27.12.2014

Yep, that's what i am trying to point here.


Re: Define. - M4D - 27.12.2014

I'm not sure but i think if you use printf to print Test, it will be print Test defined
For example
pawn Код:
#define Test True
printf("Test: %s",Test);
It will be print true

You have to use if and strcmp, so if Test defined as true, print Yes variable value

Sorry i'm on my cellphone and i can't test code

I think only way is use "if"
If someone knows other way please help me and jake :P


Re: Define. - JaKe Elite - 27.12.2014

As i said, i am trying to optimized my script that's why i am not using any strcmp, and the method you have given to me didn't work.


Re: Define. - Lordzy - 27.12.2014

Quote:
Originally Posted by _Jake_
Посмотреть сообщение
Is there any possible way to use this on displaying stuffs such as "Enable" if true and "Disable" false (print)
Is there anyway to do it without using the functions manually but this.

pawn Код:
new yes[4] = "Yes", no[3] = "No";
printf("Test: %s", TEST ? yes : no);
According to the above code, you can use simple macros to define :
pawn Код:
#define retTrueFalse(%0) (%0 == true ? ("Yes") : ("No"))

//Can be used as
new
    bool:test;

printf("%s", retTrueFalse(test));
Will print "Yes" if "test" is set to true, else "No".


Re: Define. - JaKe Elite - 27.12.2014

Is it working with the defines, i really need 'em.


Re: Define. - Lordzy - 27.12.2014

The one I did will, you can even shorten it if you want.


Re: Define. - JaKe Elite - 27.12.2014

It works however it gives me a warning

pawn Код:
redundant test: constant expression is non-zero
I don't want to make my script dirty just because of these warnings.

Any solutions for the fix of the warning?


Re: Define. - Lordzy - 30.12.2014

Quote:
Originally Posted by _Jake_
Посмотреть сообщение
It works however it gives me a warning

pawn Код:
redundant test: constant expression is non-zero
I don't want to make my script dirty just because of these warnings.

Any solutions for the fix of the warning?
Show that line where it occurs.