When do I use this?!
#1

Hello there, hope you're having a nice day,
so I observed this on many includes, people tend to use this; I tried to figure it out on my own, but I could get it, so a lot of people put this somewhere on top of their scripts
PHP код:
#if defined /*something*/
    #endinput
#endif
#define/*something*/ 
this can be found on many includes like I_ZCMD
PHP код:
#if defined _I_ZCMD_INCLUDED
    #endinput
#endif
#define _I_ZCMD_INCLUDED 
and other mapandreas based include
PHP код:
#if defined _MapAndreas_Included
    #endinput
#endif
#define _MapAndreas_Included 
I did make a ****** search, here's what I found https://sampwiki.blast.hk/wiki/Keywords:...C_.23endscript
but I still have a very weak image on it,
I'd appreciate it if anyone could give me some simple explanation, and few samples
Reply
#2

It's supposed to guard against accidentally including the same file multiple times (for example in your gamemode and in another library). But it's kind of redundant since the compiler doesn't include the same file twice unless it is specifically told to do so (using #undef _inc_filename).
Reply
#3

Vince, could this also be used to check whether a plugin has been included, such as the streamer, and use it in an if statement to make a gamemode/filterscript that will know whether or not the include has been put in?

Such as if we used the "Modular" technique, that we can make it use the streamers functions, or the natives depending on what has been included in the initial file that is being compiled?

Does this also mean, with the files, that we shouldn't be using streamer.inc as a modular filename, or zcmd (being that zcmd can be in include form)?


(I was actually thinking of this earlier on, and its funny that this was posted up questioning a borderline related scenario)
Reply
#4

Well, you can do something like this:
PHP код:
#if !defined _inc_streamer
    #error streamer plugin is required
#else
    
print("streamer included");
#endif 
Not sure if that's what you mean. Also I do think that you can't have two includes with the same name in different folders because the compiler internally defines a constant that consists of _inc_ plus the base name of the file; that is the name of the file without the path and extension.

There's a lot more information in pawn-lang.pdf.
Reply
#5

Thanks man, that was what I was asking.

This is something that isn't very much used, or discussed unless people actually 'know' about it, or stumble upon it as such.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)