Thread: Tips & Tricks
View Single Post
Old 27/01/2011, 10:31 AM   #24
Beta Tester
Y_Less's Avatar
Join Date: Jun 2008
Location: 629 -
Posts: 15,518
Reputation: 3207
Default Re: Tips & Tricks

Originally Posted by Slice View Post
The ternary operator
You may want to mention that strings in the result section of the triadic operator MUST be enclosed in brackets. This is because when I wrote the code to support compile time string concatenation and the stringize operator (#) I had to add a list of explicit characters which would end strings being stringized, such as commas and close brackets, note that this code as a result won't work:

pawn Code:
#define MY_STR(%0) #%0

printf("Hello " MY_STR(a,b));

That will in fact generate:

pawn Code:
printf("Hello a", b);

Note that I covered that in my pre-processor topic but never actually explained why. Anyway, the point is that I forgot about triadic operators and so ":" is not a valid string end character, even though it is - so you must enclose the strings in brackets to avoid lots of bizarre errors.

Originally Posted by Slice View Post
Running code just after a function finishes
You're not the only one to have done this (though I've not released the code which does it). I find this useful to apply a large set of operations at once. If you look in the YSI library YSI_td.own it can dynamically update textdraws, so you can move them about the screen or change the colour etc. If you have code which looks like this:

pawn Code:
TD_Colour(td, 0xFF0000AA);
TD_SetShadow(td, 3);
TD_Font(td, 2);

That will change the textdraw for anyone looking at it to a red style 2 TD with a shadow, however because of the way the system used to work that would have redrawn the textdraw three times when it doesn't need to. The old method of fixing this was an extra parameter:

pawn Code:
TD_Colour(td, 0xFF0000AA, false);
TD_SetShadow(td, 3, false);
TD_Font(td, 2);

So only the last update in a set would change the appearance, the new system however uses a timer in much the same way as you just described. All the functions contain this (or something similar):

pawn Code:
if (YSI_g_sTimer[td] == -1)
    YSI_g_sTimer[td] = SetTimerEx("TD_Delay", 0, 0, "i", td);

That way the "TD_Delay" function is always called after the last current update is applied, without knowing a user's code in advance.
Y_Less is online now   Reply With Quote