[Help] #define | FS - gamemode
#1

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?
Reply
#2

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

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"
Reply
#4

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

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

#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.
Reply
#7

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
Reply
#8

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;

Reply
#9

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)
Reply
#10

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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)