#define, #else,#endif
#1

Can someone explain me why this not works?
top
pawn Код:
new array=1;
init
SetTimer

pawn Код:
public Show()
{
    if(array)
    {
        #if !defined SOMETHING
            #define SOMETHING
        #endif
        print("Defined");
    }else{
        #if defined SOMETHING
            #undef SOMETHING
        #endif
        print("Undefined");
    }
    #if defined SOMETHING
    print("Defined :D");
    #else
    print("Not defined :D");
    #endif
    return 1;
}
Shows
Defined
Not defined
Defined
Not defined
Defined
Not defined
Defined
Not defined
...
Reply
#2

Pretty self explained the way i see it.

new array;
new array = 1;
__________________________________

1. Checks if SOMETHING is defined.
2. defines if SOMETHING isn't defined
3. Prints "Defined"
4. Checks if SOMETHING is defined.
5. undefines SOMETHING if it's defined.
6. prints "Undefined"
Reply
#3

#define text (1)
than
#if text (1) (or 0) .. your func #endif
Reply
#4

Quote:
Originally Posted by Gh0sT_
Посмотреть сообщение
#define text (1)
than
#if text (1) (or 0) .. your func #endif
So i've undefined symbol SOMETHING

this #define SOMETHING 1 must be on top not in ;x


>>> HELP <<<
Reply
#5

https://sampforum.blast.hk/showthread.php?tid=166680
Reply
#6

Quote:
Originally Posted by g_aSlice
Посмотреть сообщение
Nothing usefull
Reply
#7

ok none knows, so delete please this topic and thx for none help
Reply
#8

You are using the syntax on a wrong way, on a very suspicious wrong way -_-
You first check if it SOMETHING is defined, if it is NOT defined, you define it, than you check if SOMETHING is defined, if it is defined, you undefine it. You are repeating the syntax/function all the time which causes the prints. On a easier way to explain it to you, I will make it in steps:

1. You check if SOMETHING is not defined
2. If it is not defined, you define it
3. Then below it checks if SOMETHING is defined, if it is, than you undefine it
4. The syntax (#if !defines SOMETHING) on the top cheks if it is not defined
5. The last check undefined it, but the syntax on the top checks if it is not defined, if it is not, it defines again.

Sorry if it is quite difficult, I couldn't explain it on an easier way. In a line: The function/syntax you made is an endless process
Reply
#9

I know what am doing ;x i am not a noob.
i run forst time timer so array == 1 and
pawn Код:
#if !defined SOMETHING
            #define SOMETHING
        #endif
SOMETHING is NOT defined so I #define and next is
pawn Код:
#if defined SOMETHING
    print("Defined :D");
    #else
    print("Not defined :D");
    #endif
yes i define so must print
pawn Код:
Define
Defined :D
but prints
pawn Код:
Defined
Not Defined :D
why this works only here
pawn Код:
if(array)
    {
        #if !defined SOMETHING
            #define SOMETHING
        #endif
        print("Defined");
    }
but not here
pawn Код:
#if defined SOMETHING
    print("Defined :D");
    #else
    print("Not defined :D");
    #endif
too
Reply
#10

It doesn't matter what code you have between lines with #.

When compiling, your code actually looks like this:

pawn Код:
#if !defined SOMETHING
            #define SOMETHING
        #endif

        #if defined SOMETHING
            #undef SOMETHING
        #endif

    #if defined SOMETHING
    print("Defined :D");
    #else
    print("Not defined :D");
    #endif
So it will #undef SOMETHING anyway, because it comes after #define.
Reply
#11

OMG so great
pawn Код:
public Show()
{
    if(array)
    {
        #if !defined SOMETHING
            #define SOMETHING
            print("Defined");
        #endif
    }else{
        #if defined SOMETHING
            #undef SOMETHING
            print("Undefined");
        #endif
    }
    #if defined SOMETHING
    print("Defined :D");
    #else
    print("Not defined :D");
    #endif
    return 1;
}
then why not prints
Defined
Undefined
Not defined
?
Reply
#12

Because the message "Undefined" only get's printed of array is equal to 0 (or false).

If you try to remove
pawn Код:
#if defined SOMETHING
            #undef SOMETHING
            print("Undefined");
        #endif
you'll probably notice that it will print "Defined " instead of "Not defined "
Reply
#13

Lol very very... stupid, ok thx 4 explaining, solved
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)