Stock - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Stock (
/showthread.php?tid=223983)
Stock -
Anteino - 10.02.2011
If I create a variable within a stock function, will it only be valid in that stock and for that player? Or will it interact with other players using the same stocks?
Re: Stock -
Krx17 - 10.02.2011
Your question is a bit confusing.
Are you saying that if you create a variable inside a stock function, will it be accessible outside the function?
or are you asking if a variable created inside a stock will work for only one playerid, such as playerid 0?
Re: Stock -
Anteino - 10.02.2011
Quote:
Originally Posted by Krx17
Your question is a bit confusing.
Are you saying that if you create a variable inside a stock function, will it be accessible outside the function?
or are you asking if a variable created inside a stock will work for only one playerid, such as playerid 0?
|
Both I need to know!
Re: Stock -
Krx17 - 10.02.2011
If you create a variable inside a stock function, it can only be used inside that function.
If you create a variable inside a stock function, you can use it for any playerid.
Example:
pawn Код:
stock myFunc(playerid)
{
//Since playerid is part of the function parameters, you can basically use it for any playerid.
//So we can do this:
SetPlayerHealth(playerid, 0);
//And anywhere in the script we can do myFunc(1) for playerid 1 or myFunc(10) for playerid 10
}
stock myFunc2()
{
new playerid = 5;
//Since we created playerid inside the function and it's not part of the parameters
// It can only do stuff for playerid 5 unless we set 'playerid' to something else
SetPlayerHealth(playerid, 0); //Will set playerid 5's health to 0.
}
Hopefully that was what you were asking.