#define VALUE VARIABLE
#1

I made a dialog to change some defines
PHP Code:
//OnDialogResponse...case dialogid:
#undef VALUE
#define VALUE strval(inputtext) 
But when i use it example
PHP Code:
printf("VALUE = %d"VALUE); 
In this line i get error "Undefined Symbol inputtext"

and example
PHP Code:
for(new i=0i<VALUEi++) 
i get error "Undefined Symbol inputtext"

How to do it correctly?
Reply
#2

Defines are constants that get changed compile time, you need to use variables for that.
Reply
#3

Well, are you doing those things inside OnDialogResponse? Otherwise you don't have inputtext.
Reply
#4

Quote:
Originally Posted by Misiur
View Post
Well, are you doing those things inside OnDialogResponse? Otherwise you don't have inputtext.
Yes

PHP Code:
//OnDialogResponse...case dialogid: 
#undef VALUE 
#define VALUE strval(inputtext) 
Quote:
Originally Posted by PrO.GameR
View Post
Defines are constants that get changed compile time, you need to use variables for that.
I tried it..
PHP Code:
new VALUE 25
complier crashes in this line
PHP Code:
new Info[MAX_PLAYERS][VALUE][ENUM]; 
Reply
#5

Because compiler needs constants when initializing arrays, there is no memory allocation in pawn or dynamic array sizes.
Reply
#6

Quote:
Originally Posted by PrO.GameR
View Post
Because compiler needs constants when initializing arrays, there is no memory allocation in pawn or dynamic array sizes.
Noway?
Reply
#7

printf("VALUE = %d", VALUE);

pawn Code:
// ** INCLUDES

#include <a_samp>

// ** DEFINES

#define VALUE strval(inputtext)

// ** MAIN

main()
{
    print("Loaded \"blank.amx\".");

    OnDialogResponse(0, 0, 0, 0, "50");
}

// ** CALLBACKS

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    printf("%d", VALUE);
    return 1;
}
for(new i = 0; i < VALUE; i ++)

pawn Code:
// ** INCLUDES

#include <a_samp>

// ** DEFINES

#define VALUE strval(inputtext)

// ** MAIN

main()
{
    print("Loaded \"blank.amx\".");

    OnDialogResponse(0, 0, 0, 0, "50");
}

// ** CALLBACKS

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    for(new i = 0; i < VALUE; i ++)
    {
        printf("%d", i);
    }
    return 1;
}
All work.

new Info[MAX_PLAYERS][VALUE][ENUM];

Set it to the highest value being used.
Reply
#8

Quote:
Originally Posted by Shinja
View Post
Yes

PHP Code:
//OnDialogResponse...case dialogid: 
#undef VALUE 
#define VALUE strval(inputtext) 

I tried it..
PHP Code:
new VALUE 25
complier crashes in this line
PHP Code:
new Info[MAX_PLAYERS][VALUE][ENUM]; 
Declaring dynamic arrays isn't supported by PAWN, you have to have a constant value. In this case you are relying on "strval", not a constant.

Defines are just text replacements, so you are actually doing this: (not valid)
pawn Code:
new Info[MAX_PLAYERS][strval(inputtext)][ENUM];
And in case you are using "VALUE" inside of OnDialogResponse, the error should not occur.
Also i guess its meaningless to declare a macro instead of a variable here because basically you want a better readable code and don't want to process "strval" again and again. In that case, variables are helpful not macros.
pawn Code:
new VALUE = strval(inpittext);
Reply
#9

Quote:
Originally Posted by SickAttack
View Post
printf("VALUE = %d", VALUE);

pawn Code:
// ** INCLUDES

#include <a_samp>

// ** DEFINES

#define VALUE strval(inputtext)

// ** MAIN

main()
{
    print("Loaded \"blank.amx\".");

    OnDialogResponse(0, 0, 0, 0, "50");
}

// ** CALLBACKS

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    printf("%d", VALUE);
    return 1;
}
for(new i = 0; i < VALUE; i ++)

pawn Code:
// ** INCLUDES

#include <a_samp>

// ** DEFINES

#define VALUE strval(inputtext)

// ** MAIN

main()
{
    print("Loaded \"blank.amx\".");

    OnDialogResponse(0, 0, 0, 0, "50");
}

// ** CALLBACKS

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    for(new i = 0; i < VALUE; i ++)
    {
        printf("%d", i);
    }
    return 1;
}
All work.

new Info[MAX_PLAYERS][VALUE][ENUM];

Set it to the highest value being used.
That's not what i mean't, but thanks!

Thanks Gammix for explanations!
Reply
#10

Quote:
Originally Posted by Shinja
View Post
That's not what i mean't, but thanks!
Yeah, I see. The definition doesn't store values, so who knows what you were thinking. And the main post lacks of what you were trying to do.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)