![]() |
Variable Scopes?
Okay, I am a little bit confused about variable scopes, especially in gs2.
I know: this player npcs[] players[] client/r server/r var = getPlayer or findPlayer or something and then that makes a new prefix. etc. are there other variable prefixes? I mean, I just don't know. and also, what about non-prefixed vars? Are they clientside global temp? Confirm this or correct me. Okay, the other thing that is much confusing me. How in the world does passing variables within an NPC to another function work? I mean, do param named variables stay local to their function...? It's just so confusing. |
NPC Code:var = findPlayer(account); "var" becomes the prefix to player "account", i.e. var.chat Also, about passing parameters to functions. NPC Code:function onCreated() NPC Code:public function myFunction(var1, var2) In the first NPC, the expected parameters are variables "var1" and "var2", so when the function is given parameters, "var1" takes the first parameter and "var2" takes the second. The variables passed to the public function will remain local to that function in the other NPC (as in, you cannot access the parameters given to that public function in the script calling the public function) |
In the first NPC, the expected parameters are variables "var1" and "var2", so when the function is given parameters, "var1" takes the first parameter and "var2" takes the second.
The variables passed to the public function will remain local to that function in the other NPC (as in, you cannot access the parameters given to that public function in the script calling the public function)[/QUOTE] So functions passing variables should be kept in different NPCs? |
Quote:
|
NPC Code: Would the values of dx and dy set in onCreated change in that script because they are set by receiving parameters? Would they change within the function inaccurateDistance? What would be really nice to hear is that the variable scope of function params remained local to the function. |
Quote:
|
Quote:
|
Quote:
|
| All times are GMT +2. The time now is 03:25 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.