Need some help with macros - 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: Need some help with macros (
/showthread.php?tid=294944)
Need some help with macros -
Meta - 04.11.2011
Hi there!
I currently do some work with macros and got stuck at a very ugly point.
Now I got something like that.
(The code is only an example)
pawn Код:
#define moo4 1
#define moo3 2
#define moo2 3
#define moo1 4
new bool:FALSE = false;
#define UseMoo(%0) do{ new tmpstring[20]; format(tmpstring, sizeof(tmpstring), "Moo_%d", %0); CallLocalFunction(tmpstring, "d", para1); }while(FALSE)
#define MOO:%0{%1} forward Moo_%0(para1); public Moo_%0(para1) { new somevar = %0; %1 }
public OnCallMoo(id, para1)
{
UseMoo(id);
}
Moo:moo4
{
// some code
}
The problem:
Now my
Moo:moo4 is transformed to
Moo_moo4 but it should be
Moo_1 as
moo4 is defined with 1!
Also
somevar should be the definition of %0 (in that example moo4, so 1);
I get:
pawn Код:
forward Moo_moo4(para1);
public Moo_moo4(para1)
{
somevar = %0; // error, unknown symbol "" as %0 should be the definition of moo4 but is nothing somehow
// code ...
}
I need:
pawn Код:
forward Moo_1(para1);
public Moo_1(para1)
{
somevar = 1;
// code ...
}
So I need to let the precompiler use the macroes for moo1-moo4 first to replace them with their definitions and let run my code afterwards so that every moo1 etc will become its definition (fckn hard to explain >.<)
How could I do that right? Or is it impossible?

Maybe our god ****** may help
AW: Need some help with macros -
Meta - 04.11.2011
Okay, one issue I forgot to tell you is that moo4, moo3 etc are numbers used at some other place f.ex (silly example)
pawn Код:
GivePlayerMoney(playerid, moo4);
Does this work here, too?
AW: Need some help with macros -
Meta - 04.11.2011
Anyway thanks for your great code <3
//EDIT: error (the Moo: Line) Expression has no effect D: