Creating stock only if not difined - 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: Creating stock only if not difined (
/showthread.php?tid=446088)
Creating stock only if not difined -
Swimor - 24.06.2013
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?
Re: Creating stock only if not difined -
[MG]Dimi - 24.06.2013
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?
Re: Creating stock only if not difined -
MP2 - 24.06.2013
pawn Код:
#if !defined MyFunction
stock MyFunction(playerid)
{
// Code
}
#endif
That simple.
Re: Creating stock only if not difined -
Swimor - 24.06.2013
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?
Re: Creating stock only if not difined -
[MG]Dimi - 24.06.2013
Why? I guess you are doing it wrong. Can you give us pure example where you would use it?
Re: Creating stock only if not difined -
Mauzen - 24.06.2013
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.