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 08-26-2006, 03:42 AM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
Associative array?

Hi. Are associative arrays possible in GS2?

What I mean arrays where the index is a string rather than an integer. E.g. myArray["index"]?

I tried it and it appeared not to work (Though diddnt give me an error in RC.) So are they possible? Thanks.
Reply With Quote
  #2  
Old 08-26-2006, 01:40 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
You can just use subvariables, which is quite the same. Internally they are organized like an associative array, although you cannot access them as indexed array (use obj.getvarnames() to find out what variables are there, obj.savevarstoarray(sort) to transform it into an indexed array):

myarray.index or myarray.("index")
Reply With Quote
  #3  
Old 08-26-2006, 04:13 PM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
Thanks
Reply With Quote
  #4  
Old 08-27-2006, 03:57 PM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
ok, i have a few problems.

Heres what i'm trying to do:

PHP Code:
for (plplayers) {
  
olplayers.players.(pl.account) = {pl.level,pl.x,pl.y};
 }
 
player.chat olplayers.getvarnames(); 
I'm trying to create an index with the name of the players account. It's showing up as "account" in getvarnames. Where the index should be the name of the player. How can I make it understand that pl.account is a variable that needs to be interpreted?
Reply With Quote
  #5  
Old 08-27-2006, 05:14 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
Try olplayers.players.(@ pl.account).
Reply With Quote
  #6  
Old 08-27-2006, 06:02 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Yes you need to tell that it is a string, by doing "" @ pl.account or just @ pl.account
Reply With Quote
  #7  
Old 08-27-2006, 06:08 PM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
Thanks that works but I cant use it how I want to.

I'm trying to script a map.

Instead of having each client checking the locations of each other player while they're viewing the map I intend to have a database NPC store the locations and get them every 0.5 seconds if there is someone viewing the map. Then, each player can get the data from the database NPC rather than getting the information themselves.

However, I have a problem. I cant seem to pass associative arrays as params from one npc to another.

Heres what I have so far:

MapDB NPC
PHP Code:
public function pollInfo() {
playernames.clear();
oldplayers.clear();
for (
plplayers) {
  
olplayers.(@ pl.account) = {pl.level,pl.x,pl.y};
  
playernames.add(pl.account);
 }
}

public function 
getPlayerNames() {
  return 
playernames;
}

public function 
getLocations() {
  return 
olplayers;


part of Map NPC
PHP Code:
function onActionServerside() {
//retrieve data from the mapdb npc
mapdb findnpc("MapDB");
mapdb.pollInfo();
playernames mapdb.getPlayerNames();
locations mapdb.getLocations();
//send data back to the client
player.chat  locations//Does not contain any account names, but it should.
triggeraction(0,0,"clientside","Map",playernames,locations);

}
//#CLIENTSIDE 
Playernames gets returned correctly but locations is not. It loses the subvariables that have been set.
Reply With Quote
  #8  
Old 08-27-2006, 06:14 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
try

PHP Code:
player.chat locations
instead of

PHP Code:
player.chat  locations
?
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #9  
Old 08-27-2006, 06:20 PM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
actually it should have been
PHP Code:
player.chat locations.getvarnames(); 
I changed it to see if playernames would get passed correctly. Then changed it back and forgot to add .getvarnames. But still, it doesn't contain any account names.
Reply With Quote
  #10  
Old 08-27-2006, 06:42 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
I dont see any OBVIOUS faults in it, but then im not really looking too closely at it.

Perhaps
PHP Code:
olplayers.(@pl.account
instead of
PHP Code:
olplayers.(@ pl.account
? No idea..
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #11  
Old 08-27-2006, 11:44 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
That's not the problem. When you want to pass variables to the clientside or display it as string then you need to convert it into a string or array first (which is then converted to a string automatically). Use oldplayers.savevarstoarray(false) for that, or eventually directly work with an array in this case, like olplayers.add({pl.account,pl.level,pl.x,pl.y});
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 07:18 PM.


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