SA-MP Forums Archive
How to give a variable a value, that will also be read from a predefined value? - 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: How to give a variable a value, that will also be read from a predefined value? (/showthread.php?tid=447127)



How to give a variable a value, that will also be read from a predefined value? - 101 - 28.06.2013

Lets say I got

new license[1][128]
if (nolicense[playerid]) license[0] = "$1000";

This works, however how would I make it so I can predefine the $1000 in the top of the script? For example


#define LICENSE_PRICE 1000;

And use it like this

new license[1][128]
if (nolicense[playerid]) license[0] = "$%d", LICENSE_PRICE; (ofcourse this wont work) but is there aw ay for it to work?


Re: How to give a variable a value, that will also be read from a predefined value? - IstuntmanI - 28.06.2013

#define LICENSE_PRICE 1000


Re: How to give a variable a value, that will also be read from a predefined value? - 101 - 28.06.2013

Thats not what I mean, obviously I know how to do that.... I'm asking you guys what to do, to use it in this example down here:

new license[1][128]
if (nolicense[playerid]) license[0] = "$1000";


Re: How to give a variable a value, that will also be read from a predefined value? - Vince - 28.06.2013

Why are you storing it as a string anyway? You can just format it when it needs to be sent to the output.


Re: How to give a variable a value, that will also be read from a predefined value? - Scenario - 28.06.2013

You cannot set the default value of any variable in an array. Since a string is basically an array, you cannot set its default value. The only way to do this would be to do something like this under OnGameModeInit() or something:

pawn Код:
license[0] = "$1000";
license[1] = "$1000";
However, Vince's solution is probably the least problematic.


Re: How to give a variable a value, that will also be read from a predefined value? - 101 - 28.06.2013

Quote:
Originally Posted by Vince
Посмотреть сообщение
Why are you storing it as a string anyway? You can just format it when it needs to be sent to the output.
Because in the script its
if (nolicense[playerid]) license[0] = "{COLOR CODE}$1000";
else if (havelicense[playerid]) license[0] = "{COLOR CODE}$500";

Then its

format(gstring, sizeof(gstring), "The price is d", $license[0]);
SendClientMessage(playerid, COLOR_GREEN, gstring);