SA-MP Forums Archive
Define problem - 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: Define problem (/showthread.php?tid=280885)



Define problem - gamer931215 - 03.09.2011

Hey guys, im planning to make a kickass Dialog processor, but i have a problem...

pawn Код:
#define MAX_DIALOGS 50
new bool:DIALOG_USED[MAX_DIALOGS];
#define DIALOG_%0(%1,%2,%3,%4,%5,%6)    forward DIALOG_%0(%1,%2,%3,%4,%5,%6);   \
                                        DIALOG_USED[%0] = true;                 \
                                        public DIALOG_%0(%1,%2,%3,%4,%5,%6)

DIALOG_0(playerid, response, listitem, inputtext[]) //gets a warning: warning 203: symbol is never used: "DIALOG_0"
{
    print("Test");
    return 1;
}

//This function will be called later at OnDialogResponse...
HOWEVER this works:
pawn Код:
DIALOG_0(playerid, response, listitem, inputtext[]);
public DIALOG_0(playerid, response, listitem, inputtext[])
{
    print("Test");
    return 1;
}
This means there is something wrong in the define... not defining the "public" part.


Re: Define problem - Speed - 03.09.2011

pawn Код:
#define DIALOG_%1%0(%2,%3,%4,%5,%6,%7)    forward%0DIALOG_%1(%2,%3,%4,%5,%6,%7);   \
                                        DIALOG_USED[%1] = true;                 \
                                        public%0DIALOG_%1(%2,%3,%4,%5,%6,%7)
try this...


Re: Define problem - gamer931215 - 03.09.2011

Quote:
Originally Posted by Speed
Посмотреть сообщение
pawn Код:
#define DIALOG_%1%0(%2,%3,%4,%5,%6,%7)    forward%0DIALOG_%1(%2,%3,%4,%5,%6,%7);   \
                                        DIALOG_USED[%1] = true;                 \
                                        public%0DIALOG_%1(%2,%3,%4,%5,%6,%7)
try this...
Why would you put the %0 there ?
anyway i tested it (just to try, you'l never know ) but still the same warning/problem


Re: Define problem - gamer931215 - 03.09.2011

Quote:
Originally Posted by ******
Посмотреть сообщение
You can't assign to a variable outside a function. Also, you can't do "DIALOG_%0" because the compiler is "greedy", when it sees "DIALOG_0" it will NOT call "DIALOG_" with %0=0, because "DIALOG_0" is a valid symbol. Imagine if this were not the case:

pawn Код:
#define a ++

main()
{
}
Your code is now:

pawn Код:
m++in()
{
}
Hmm, i never worked much with defines before, so i just looked at ZCMD how that worked:
#define COMMAND:%1(%2) \
forward cmd_%1(%2); \
public cmd_%1(%2)

Any other idea how i can make a "callback" like zmd/dini then?


Re: Define problem - gamer931215 - 03.09.2011

Quote:
Originally Posted by ******
Посмотреть сообщение
Yes, the difference is that ZCMD uses ":", not "_" - it's a small but important different as colons aren't valid identifier characters, whereas underscores are.
Hmm i tried changing it, but im obviously doing something wrong again :P since DIALOG:0 becomes NULL (aka "")

pawn Код:
#define DIALOG:%0(%1,%2,%3,%4,%5,%6)    forward DIALOG:%0(%1,%2,%3,%4,%5,%6);   \
                                        DIALOG_USED[%0] = true;                 \
                                        public DIALOG:%0(%1,%2,%3,%4,%5,%6)

DIALOG:0(playerid, response, listitem, inputtext[])
{
    print("Test");
    return 1;
}

//And this is how i call the function at OnDialogResponse:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(DIALOG_USED[dialogid] == true)
    {
        new function[32];format(function,sizeof function,"DIALOG:%i",dialogid);
        return CallLocalFunction(function,"iiis",playerid,response,listitem,inputtext);
    }
    return CallLocalFunction("SD_OnDialogResponse","iiiis",playerid,dialogid,response,listitem,inputtext);
}
//Learnt this from you before you released Y_Hooks =P
#if defined _ALS_OnDialogResponse
    #undef OnDialogResponse
#else
    #define _ALS_OnDialogResponse
#endif
#define OnDialogResponse SD_OnDialogResponse
forward SD_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
Errors:
"D:\Projecten\sampserver\filterscripts\test.pwn(54 ) : error 020: invalid symbol name ""
D:\Projecten\sampserver\filterscripts\test.pwn(57) : error 010: invalid function or declaration
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


2 Errors.


Re: Define problem - iPLEOMAX - 03.09.2011

I can't help you much here, but one thing as ****** already said:

#define DIALOG:%0(%1,%2,%3,%4,%5,%6) forward DIALOG:%0(%1,%2,%3,%4,%5,%6); \
DIALOG_USED[%0] = true; \
public DIALOG:%0(%1,%2,%3,%4,%5,%6)


Simply means:

pawn Код:
forward DIALOG:Something(params..);

DIALOG_USED[Something] = true; //You cannot use this outside any function.

public DIALOG:Something(params..) {}



Re: Define problem - gamer931215 - 03.09.2011

Okay, does someone have a tutorial for me then on how to make such commands like ZCMD/dcmd does ?