![]() |
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. |
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") |
Thanks :)
|
ok, i have a few problems.
Heres what i'm trying to do: PHP Code:
|
Try olplayers.players.(@ pl.account).
|
Yes you need to tell that it is a string, by doing "" @ pl.account or just @ pl.account
|
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:
part of Map NPC PHP Code:
|
try
PHP Code:
PHP Code:
|
actually it should have been
PHP Code:
|
I dont see any OBVIOUS faults in it, but then im not really looking too closely at it.
Perhaps PHP Code:
PHP Code:
|
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});
|
| All times are GMT +2. The time now is 12:38 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.