#define VALUE VARIABLE -
Shinja - 13.08.2016
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=0; i<VALUE; i++)
i get error
"Undefined Symbol inputtext"
How to do it correctly?
Re: #define VALUE VARIABLE -
PrO.GameR - 13.08.2016
Defines are constants that get changed compile time, you need to use variables for that.
Re: #define VALUE VARIABLE -
Misiur - 13.08.2016
Well, are you doing those things inside OnDialogResponse? Otherwise you don't have inputtext.
Re: #define VALUE VARIABLE -
Shinja - 13.08.2016
Quote:
Originally Posted by Misiur
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
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];
Re: #define VALUE VARIABLE -
PrO.GameR - 13.08.2016
Because compiler needs constants when initializing arrays, there is no memory allocation in pawn or dynamic array sizes.
Re: #define VALUE VARIABLE -
Shinja - 13.08.2016
Quote:
Originally Posted by PrO.GameR
Because compiler needs constants when initializing arrays, there is no memory allocation in pawn or dynamic array sizes.
|
Noway?
Re: #define VALUE VARIABLE -
SickAttack - 13.08.2016
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.
Re: #define VALUE VARIABLE -
Gammix - 13.08.2016
Quote:
Originally Posted by Shinja
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);
Re: #define VALUE VARIABLE -
Shinja - 13.08.2016
Quote:
Originally Posted by SickAttack
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!
Re: #define VALUE VARIABLE -
SickAttack - 13.08.2016
Quote:
Originally Posted by Shinja
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.