Creating stock only if not difined
#1

Hello,

I want to build macro that will create stock only if the stock not exists, for example:
Код:
#define mystock%0@%2(%1) \
    #if !defined %0@0 \
        stock%0@0(%1) \
    #else \
        stock%0@%2(%1) \
    #endif
But it will not work... Is there any way to do this?
Reply
#2

pawn Код:
#if !defined [what has to be defined]
   
#define [define here]

#endif
But I don't quite understand why are you using %0 and so on. Is it only one stock you want to add to script in case it doesn't exist?
Reply
#3

pawn Код:
#if !defined MyFunction

stock MyFunction(playerid)
{
    // Code
}

#endif
That simple.
Reply
#4

Quote:
Originally Posted by MP2
Посмотреть сообщение
pawn Код:
#if !defined MyFunction

stock MyFunction(playerid)
{
    // Code
}

#endif
That simple.
Dead you read my first comment?

This is what I want to do!:
Код:
#define mystock%0@%2(%1) \
    #if !defined %0@0 \
        stock%0@0(%1) \
    #else \
        stock%0@%2(%1) \
    #endif
So simple?
Reply
#5

Why? I guess you are doing it wrong. Can you give us pure example where you would use it?
Reply
#6

His point is to have one define for all stocks, not one define for each function, so you could do stuff like

pawn Код:
mystock function1(params) {
    printf("blablabla");
}

//this one will be ignored
mystock function1(params) {
    printf("albalbalb");
}
As far as i know this isnt possible, as you cant access the function body in a define, so you could only affect the header of the function, but not leave out the whole function.
I also suggest you to avoid redefining function like this again and again. It will get harder to see which function really is used if you got 5 different ones spread over your gamemode and all the includes.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)