SA-MP Forums Archive
[Help] #define | FS - gamemode - 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: [Help] #define | FS - gamemode (/showthread.php?tid=650806)



[Help] #define | FS - gamemode - Hend - 07.03.2018

FS:
Код:
public OnFilterScriptInit()
{
	#define teszt
	
	return 1;
}

public OnFilterScriptExit()
{
	#undef teszt

	return 1;
}
Gamemode:
Код:
	#if defined teszt
		Msg(playerid, "Teszt");
	#endif
Why don't work?


Re: [Help] #define | FS - gamemode - MrThomas - 07.03.2018

What doesn't work, post the error if it appears or explain what's not working.


Re: [Help] #define | FS - gamemode - Hend - 07.03.2018

Quote:
Originally Posted by MrThomas
Посмотреть сообщение
What doesn't work, post the error if it appears or explain what's not working.
No have error / warning code.
Код:
>Exit code: 0    Time: 8.609
Player don't receive message "teszt"


Re: [Help] #define | FS - gamemode - Dayrion - 07.03.2018

Because you declared "teszt" as local define exclusively for OnFilterScriptInit().


Re: [Help] #define | FS - gamemode - Hend - 07.03.2018

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
Because you declared "teszt" as local define exclusively for OnFilterScriptInit().
Then how can I define global? Or not possible?


Re: [Help] #define | FS - gamemode - GaByM - 07.03.2018

#define does not act like a normal variable

Once you #define something it is present in the whole documnet until you use #undef.
This is your problem:

PHP код:
public OnFilterScriptInit()
{
    
#define teszt
    //here you defined it
    
return 1;
}
public 
OnFilterScriptExit()
{
        
//if you do a check here teszt is defined at this line
    #undef teszt
       // after this line you no longer can use teszt because there is no longer defined
    
return 1;
}
CMD:teszt(playeridparams[])
{
       
//this doesn't work because testz was undefined.
    #if defined teszt
        
Msg(playerid"Work");
    
#else
        
Msg(playerid"Don't work");
    
#endif
    
return 1;

Read more here: https://sampforum.blast.hk/showthread.php?tid=570933
I know it is a lot to read, but at least try to read the first few paragraphs.


Re: [Help] #define | FS - gamemode - jasperschellekens - 07.03.2018

I think he should just put #define teszt on top of his script where all defines are.
I guess placing it under onfilterscriptinit only makes it work under onfilterscriptinit.
So put it on top and remove #undef teszt


Re: [Help] #define | FS - gamemode - Hend - 07.03.2018

Quote:
Originally Posted by jasperschellekens
Посмотреть сообщение
I think he should just put #define teszt on top of his script where all defines are.
I guess placing it under onfilterscriptinit only makes it work under onfilterscriptinit.
So put it on top and remove #undef teszt
Don't work.

FS: (teszt.pwn)
PHP код:
#include <a_samp>
#include <plugin/streamer>
#include <plugin/sscanf2>
#define teszt
public OnFilterScriptInit()
{
    
printf("    FS loaded.");
    
    return 
1;
}
public 
OnFilterScriptExit()
{
    
printf("    FS unloaded.");
    return 
1;

Gamemode:
PHP код:
CMD:teszt(playeridparams[])
{
    
#if defined teszt
        
Msg(playerid"Work");
    
#else
        
Msg(playerid"Don't work");
    
#endif
    
return 1;




Re: [Help] #define | FS - gamemode - GaByM - 07.03.2018

My bad, now I see. You define teszt in a filterscript but you want to check the definition in your gamemode.

This is not possible! You can solve this by either using PVar (see here https://sampforum.blast.hk/showthread.php?tid=163175).
Another way is to #include your filterscript in your gamemode. (so now: your FS is part of your gamemode + you shouldn't compile the gamemode & FS, only the gamemode + remove teszt from the filterscript)


Re: [Help] #define | FS - gamemode - RedFusion - 07.03.2018

Here's a fix for your problem:

Filterscript:
pawn Код:
#define FS_PROPERTY_NAME \
    "MyTestProperty123"

public OnFilterScriptInit() {
    if( existproperty(.name = FS_PROPERTY_NAME) ) {
        print("property could not be created, it already exists!");
    } else {
        setproperty(.name = FS_PROPERTY_NAME);

        if( existproperty(.name = FS_PROPERTY_NAME) ) {
            print("property created successfully.");
        } else {
            print("property could not be created!");
        }
    }
}

public OnFilterScriptExit() {
    if( existproperty(.name = FS_PROPERTY_NAME) ) {
        deleteproperty(.name = FS_PROPERTY_NAME);

        if( !existproperty(.name = FS_PROPERTY_NAME) ) {
            print("property deleted");
        } else {
            print("property could not be deleted");
        }
    } else {
        print("property does not exist");
    }
    print("property fs unloaded");
}
Gamemode:
pawn Код:
#define FS_PROPERTY_NAME \
    "MyTestProperty123"

CMD:teszt(playerid, params[]) {
    if( existproperty(.name = FS_PROPERTY_NAME) ) {
        Msg(playerid, "Work");
    } else {
        Msg(playerid, "Don't work");
    }
    return 1;
}