Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 10-17-2005, 07:20 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
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.
Reply With Quote
  #2  
Old 10-17-2005, 12:59 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
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()
{
echo(findNPC("foo").myFunction("zombies", "ninjas"));
}


NPC Code:
public function myFunction(var1, var2)
{
return("The first variable is equal to '" @ var1 @ "' and my second is equal to '" @ var2 @ "'.");
/*
In effect:

var1 = "zombies";
var2 = "ninjas";
*/
}


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)
__________________
Skyld
Reply With Quote
  #3  
Old 10-17-2005, 05:34 PM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
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?
Reply With Quote
  #4  
Old 10-17-2005, 06:42 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by jake13jake
So functions passing variables should be kept in different NPCs?
What do you mean?
__________________
Skyld
Reply With Quote
  #5  
Old 10-17-2005, 07:49 PM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
NPC Code:

//ex.
function onCreated() {
dx = 2;
dy = 5;
setTimer(5);
}

function onTimeout() {
distance = inaccurateDistance(9,20);
}

function inaccurateDistance(dx,dy) {
dx-=2
dy-=2
return (dx^2+dy^2) ^0.5;
}



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.

Last edited by jake13jake; 10-17-2005 at 08:02 PM..
Reply With Quote
  #6  
Old 10-17-2005, 09:49 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by Skyld
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)
I think he already answered that question?
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #7  
Old 10-17-2005, 09:53 PM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Quote:
Originally Posted by ApothiX
I think he already answered that question?
well, actually, does the function he speaks of come out of a different NPC or is it within the same NPC as when it is called, It's just his wording confuses me.
Reply With Quote
  #8  
Old 10-18-2005, 01:55 AM
Lance Lance is offline
dark overlord
Lance's Avatar
Join Date: Sep 2003
Location: Space Jam Mountain
Posts: 5,072
Lance is on a distinguished road
Quote:
Originally Posted by jake13jake
What would be really nice to hear is that the variable scope of function params remained local to the function.
That's what he said...?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 11:44 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.