+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: How to use #ifdef

  1. #1
    Wire Amateur brutell's Avatar
    Join Date
    Jun 2009
    Posts
    34

    Default How to use #ifdef

    While using e2, you might find that some servers have plugins, like propcore, and others do not. Unfortunately, if you script your e2 to take advantage of a plugin, then it will error on servers that do not have the plugin.

    However, one may use the functionality of #ifdef to avoid that.

    #ifdef allows the e2 to check if a function exists. Not what it returns, but if the function is defined at all. However, it checks IF A FUNCTION IS DEFINED (Hi, jason!), NOT THE VARIABLE IT RETURNS!

    Usage is like so-
    Code:
    #ifdef argument:aFunction( argument )
    #else
    #endif
    The main part is the bit after ifdef. When using ifdef, the script has to know what arguments to check. If it doesn't know, then it will check for the wrong function. One mistake that may be made is as such
    Code:
    #ifdef applyForce()
    print( "Applyforce is defined." )
    #else
    print( "Applyforce isn't defined." )
    #endif
    However, this will never be true. applyForce requires a vector, and thus when it checks for applyForce without the vector, it doesn't find a function, and so goes to the else.

    You have to provide the proper types of arguments. If the function takes a vector, you would write
    Code:
    #ifdef applyForce( vector )
    This would return true, unlike our earlier check. The same goes for array, number, string, etc.

    You may be thinking at this point, "What use would this have to me?"
    Well, it would, as mentioned above, allow you to check if the server has a plugin. For example,
    Code:
    #ifdef entity:setPos( vector )
    #else
    #endif
    This would allow you to check if you could teleport your entities, as opposed to applyForcing them into place, for example
    Code:
    #ifdef entity:setPos( vector )
    Prop:setPos( AVariablePosition )
    #else
    Prop:applyForce( ( AVariablePosition - Prop:pos() - Prop:vel() / 2 ) * Prop:mass() )
    #endif
    Additionally, its possible to forsake the #else, but it would be kind of pointless. You could at least print a warning and selfDestruct, or something.

    Code:
    #ifdef notAFunction()
    print( "Wow." )
    #endif
    Well, I really can't think of anything else, so if you can think of anything, let me know. I think there was a guide before, but I searched and couldn't find one.
    Last edited by brutell; 03-06-2010 at 02:00 PM.
    AKA Whitewater (Of said name's server)
    How to use #ifdef

  2. #2
    Wire Sofaking Unsmart's Avatar
    Join Date
    Dec 2008
    Location
    Belgium OR BANland
    Posts
    1,965

    Default Re: How to use #ifdef

    Nice, and detailed tut.

    /votesticky
    New server IP: 89.238.160.17:27018
    Hologram contraptions 1 Holo contraptions 2 EGP stuff Holo minigun Holo javelin rocket launcher
    Unsmart: I doubt the intelligence of some people.
    Drunkie: Nobody could have said that any better than Unsmart.

    Unsmart: Solece, I totally did your mom yesterday
    Solece: Who hasnt

    Divran: there are more retarded people than there are clever people in this world

  3. #3
    Wire Sofaking vexx21322's Avatar
    Join Date
    Dec 2008
    Location
    Co, united states
    Posts
    424

    Default Re: How to use #ifdef

    Wow, I was just thinking about this and trying to use it, then I come to wiremod.com and you have a thread about it...
    Have you checked HERE first?

  4. #4
    billywitchdoctor.com Schilcote's Avatar
    Join Date
    Jan 2009
    Location
    There.
    Posts
    2,006

    Default Re: How to use #ifdef

    I didn't know E2 had preprocessor directives...


    [19:16:47]Client "rcdraco" spawned in server
    [19:17:10]rcdraco: hamburgertime
    [19:18:04]rcdraco was killed by worldspawn
    [19:21:50]Dropped "rcdraco" from server

  5. #5
    Developer Matte's Avatar
    Join Date
    Jan 2009
    Location
    Norway
    Posts
    3,109

    Default Re: How to use #ifdef

    Quote Originally Posted by Schilcote View Post
    I didn't know E2 had preprocessor directives...
    @name
    @inputs
    @outputs
    @persist
    @trigger
    @model
    "If anybody says he can think about quantum physics without getting giddy, that only shows he has not understood the first thing about them."
    -- Niels Bohr

  6. #6
    Wire Sofaking jacoby6000's Avatar
    Join Date
    Feb 2008
    Location
    behind you when you aren't looking
    Posts
    792

    Default Re: How to use #ifdef

    Sooo...
    Code:
    #ifdef holoModelAny(Number,String)
    holoModelAny(N,E:model())
    #else
    holoModel(N,"")
    #endif
    Is that correct?
    Quote Originally Posted by Garrysmod View Post
    Warning: You're trying to render in the wrong place. This doesn't play nice with multi-core rendering, so we're not going to let you draw here.
    I'm not stupid!
    In [his] experience that was a sentence never to be uttered except to prove its own inaccuracy
    --Orson Scott Card

  7. #7
    billywitchdoctor.com Schilcote's Avatar
    Join Date
    Jan 2009
    Location
    There.
    Posts
    2,006

    Default Re: How to use #ifdef

    Quote Originally Posted by Matte View Post
    @name
    @inputs
    @outputs
    @persist
    @trigger
    @model
    No, those aren't preprocessor directives. They're settings for the chip. Preprocessor directives change the way code is compiled. Those affect the low level operations of the E2.


    [19:16:47]Client "rcdraco" spawned in server
    [19:17:10]rcdraco: hamburgertime
    [19:18:04]rcdraco was killed by worldspawn
    [19:21:50]Dropped "rcdraco" from server

  8. #8
    Developer Matte's Avatar
    Join Date
    Jan 2009
    Location
    Norway
    Posts
    3,109

    Default Re: How to use #ifdef

    Quote Originally Posted by Schilcote View Post
    No, those aren't preprocessor directives. They're settings for the chip. Preprocessor directives change the way code is compiled. Those affect the low level operations of the E2.
    Preprocessor directives are just commands that instructs the compiler, and that doesn't directly affect the code. The directives I mentioned fall under this category. If you're still disagreeing, look at some of the posts of 'The Master' (Syranide), himself. He calls them directives.
    "If anybody says he can think about quantum physics without getting giddy, that only shows he has not understood the first thing about them."
    -- Niels Bohr

  9. #9
    Wirererer NikoKun's Avatar
    Join Date
    May 2008
    Posts
    124

    Default Re: How to use #ifdef

    We need more tutorials on these sorts of things. I'm glad someone finally did this one, I've wondered about it for a while. Thanks!
    ------------------------------------
    aka "Nik of the Wired" in gmod.

  10. #10
    Wire Sofaking ktccd's Avatar
    Join Date
    Sep 2009
    Posts
    751

    Default Re: How to use #ifdef

    This was taught to me in a server once... It was, by far, the MOST useful anyone has ever taught me in E2. Now I can use propcore without breaking stuff! I implemented this in my spike sphere ^^.

    Well:
    Additionally, its possible to forsake the #else, but it would be kind of pointless. You could at least print a warning and selfDestruct, or something.
    That made me lol. "I mean come on! At the very least you could blow it up!"

+ Reply to Thread
Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots