Question about Variables -
CoDeZ - 02.08.2012
Hello guys , if i have a variable under ZCMD for example
pawn Code:
CMD:duel(playerid,params[])
{
new Money,targetid[24];
if(sscanf(params,"ud",targetid,Money)) return SendClientMessage(playerid,-1,"usage:blablabla");
return 1;
}
OnPlayerDeath(playerid,killerid,reason);
{
if(killerid!=INVALID_PLAYER_ID)
{
new Money;
givePlayerMoney(killerid,Money);
}
return 1;
}
question is , will the variable value will get saved and if i typed for example:
Will the variable get saved and give 500$ to killer id?
Re: Question about Variables -
SEnergy - 02.08.2012
-next reply
Re: Question about Variables -
CoDeZ - 02.08.2012
What's the difference then?
static remembers the value and saves it?
Re: Question about Variables -
SEnergy - 02.08.2012
Quote:
Originally Posted by CoDeZ
What's the difference then?
static remembers the value and saves it?
|
edit: nope, I got them wrong :X you have to create global variables
Re: Question about Variables -
Dan. - 02.08.2012
Targetid is a variable in your code, so change:
to:
Re: Question about Variables -
oKzrh - 02.08.2012
If your variable is inside your command (as you've showed to us) Than it won't be a global variable that you can actually use in your script.
In the top of your mod, under all of your includes, defines, etc... Where you probably have variables there, just add the "Money" variable, and then you'll be able to use it in your whole script, without using stating it as a new ("new") variable each time

.
Re: Question about Variables -
CoDeZ - 02.08.2012
Quote:
Originally Posted by SEnergy
yes, local variables (declared within a function) are destroyed after function ends, if you create new variable with same name it will remember it's value from previous declaration, therefore you don't need to have global variables but you can create static variables everytime you want to use them
|
Alright thanks. RPed+.
Quote:
Originally Posted by Dan.
Targetid is a variable in your code, so change:
to:
|
Thanks for fixing this one i got it fixed on my script was just giving an example here
Quote:
Originally Posted by oKzrh
If your variable is inside your command (as you've showed to us) Than it won't be a global variable that you can actually use in your script.
In the top of your mod, under all of your includes, defines, etc... Where you probably have variables there, just add the "Money" variable, and then you'll be able to use it in your whole script, without using stating it as a new ("new") variable each time  .
|
Thank you , i'll add them in the top of my script because i've got a lot of variables though , converting them to static would take some time.
RPed+
Re: Question about Variables -
oKzrh - 02.08.2012
Quote:
Originally Posted by CoDeZ
Alright thanks. RPed+.
Thank you , i'll add them in the top of my script because i've got a lot of variables though , converting them to static would take some time.
RPed+
|
Glad you're happy

.
Thanks for the Rep

!
Re: Question about Variables -
Misiur - 02.08.2012
Oh my fck sides
Quote:
Originally Posted by SEnergy
if you create new variable with same name it will remember it's value from previous declaration, therefore you don't need to have global variables but you can create static variables everytime you want to use them
|
Mr SEnergy, you just won the contest for most retarded sentence
in the history of the Internet!
https://sampwiki.blast.hk/wiki/Scripting_Basics#Scope - read this. Once, twice, or even infinite times, I don't care - just as much as you need to understand basic concept of scope and the word "local". When you get this right, you can start helping others.
End of rant