Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   2-dimensional arrays? do they exist? (https://forums.graalonline.com/forums/showthread.php?t=79635)

Stryke 05-05-2008 03:50 AM

2-dimensional arrays? do they exist?
 
Because I'm trying to make a Guild system, and it supports up to 100 guilds.
I'm using the array for the list of guilds:

serverr.guild_list

But how would I store the information of the guilds in serverr.guild_list?
If there were 2-D arrays, it would work as simple as this:

serverr.guild_list[5,1] = "Bob";

The 2nd index is 1, which represents the leader of the guild.
The guild with the index of 5, will have the leader set to the player "Bob".
The second index would be used to store all the information about the guilds.

But then again, this would work too, wouldn't it?

server.guild_list[5] = "Champions|Bob"

for(i=0;i<100;i++) {
temp.guild_list = serverr.guild_list[i].tokenize(|);
if(#t(0) == "Champions") {
for(i=0;i<10;i++)
{
this.view_guild_list[i] = #t(i)
}
}
}

Programmer 05-05-2008 03:52 AM

Of course, Do this:

PHP Code:

temp.anArray = new [5][5]; 

Will produce a 5x5 array.

To edit it, simply do:
PHP Code:

temp.anArray[0][0] = "foo!";
temp.anArray[0][1] = "bar!";
temp.anArray[1][0] = "baz!"


cbk1994 05-05-2008 03:54 AM

That's a silly way to do it. I would have an array of your guilds, and then do something like:

this.( @ "guild_" @ guildname ).members = { "cbkbud", "cbk1994", "Stefan" };

Stryke 05-05-2008 04:47 AM

Thanks. Exactly what I need. Meh now I have to change my guild manager script to 2d guild_list arrays though.

Admins 05-05-2008 01:44 PM

You can use twodimensional arrays like array[1][2], for your purpose it will be better to store them in separate variables, like

serverr.guilds = {"Samurai","Dustari"};
serverr.guild_Samurai = {me, you, etc};

Otherwise the whole array needs to be sent whenever you do a modification to a single guild.

cbk1994 05-05-2008 10:18 PM

Quote:

Originally Posted by Stefan (Post 1389167)
You can use twodimensional arrays like array[1][2], for your purpose it will be better to store them in separate variables, like

serverr.guilds = {"Samurai","Dustari"};
serverr.guild_Samurai = {me, you, etc};

Otherwise the whole array needs to be sent whenever you do a modification to a single guild.

That'd be a silly thing to use serverr for, as it has little use on clientside, and (from what I've heard, but may be false) can slow down the server if you have too many serverr flags (again, may be false).

Better to use a DB NPC.

Chompy 05-05-2008 10:21 PM

Quote:

Originally Posted by cbkbud (Post 1389181)
That'd be a silly thing to use serverr for, as it has little use on clientside, and (from what I've heard, but may be false) can slow down the server if you have too many serverr flags (again, may be false).

Better to use a DB NPC.

DB npc server you have to be serverside to retrieve info.
Why would the amount of server flags slow down a server?

What Stefan suggested is actually easier and more efficient in terms of editing variables(/guilds in this case)..

cbk1994 05-05-2008 10:38 PM

Quote:

Originally Posted by Chompy (Post 1389182)
DB npc server you have to be serverside to retrieve info.
Why would the amount of server flags slow down a server?

What Stefan suggested is actually easier and more efficient in terms of editing variables(/guilds in this case)..

It's more organized and easier to back up if it's in a DB NPC.

Plus, any idiot can make a script that says serverr.guilds = { "PIELOL" }; and erase everything.

This would add atleast some protection (for example, you could use callstack, and have everything in a TStaticVar() which saves constantly backups).

Just my opinion; and like I said, I was told that too many serverr vars can lag the server, like I said it may be false.

I would think this to be more organized anyway, but I guess personal preference anyway.

Also, you wouldn't really need to access this on clientside, as player.guild has to be set serverside (and, more secure).

Admins 05-05-2008 10:55 PM

Well it depends on if you want to display the information on client-side, of course serverr. vars should be avoided if that is not required

Stryke 05-06-2008 02:15 AM

How do I set an array's name to serverr.guilds_params[1] though?

params[1] is the Guild Name of the guild being added to the system.

something like this wont work ? setarray(serverr.guild_params[1],10);

Robin 05-06-2008 02:35 AM

I mean, I don't know, maybe I'm being silly, maybe it defeats the object, but I'd rather use the built in guild functionality?

PHP Code:

addguildmember(guild,account,nick);
//adds player to a guild (server-side)
removeguildmember(guild,account,nick);
//removes a player from a guild (server-side)
removeguild(guild);
//deletes a guild (server-side) 


Stryke 05-06-2008 03:03 AM

You won't know the total list of guilds using that, and you can't add guilds.
Can someone answer my question?

Robin 05-06-2008 03:11 AM

Specifying addguildmember("Non existant guild", "Robin", "Robin); would allow me to set my nick to Robin (Non existant guild) it's not so hard.

And your question has already been answered.

Quote:

Originally Posted by cbkbud (Post 1389137)
That's a silly way to do it. I would have an array of your guilds, and then do something like:

this.( @ "guild_" @ guildname ).members = { "cbkbud", "cbk1994", "Stefan" };

Quote:

Originally Posted by cbkbud (Post 1389137)
this.( @ "guild_" @ guildname ).members = { "cbkbud", "cbk1994", "Stefan" };

Quote:

Originally Posted by cbkbud (Post 1389137)
this.( @ "guild_" @ guildname )

Quote:

Originally Posted by cbkbud (Post 1389137)
this.( @ "guild_" @ guildname )


Stryke 05-06-2008 03:22 AM

Nice. Thanks!

One question: Is there a way to delete an array?

Programmer 05-06-2008 03:26 AM

Quote:

Originally Posted by Stryke (Post 1389244)
Nice. Thanks!

One question: Is there a way to delete an array?

temp.array = null;

cbk1994 05-06-2008 03:27 AM

EDIT: You beat me to it, Ian! If I'd have posted 30 seconds earlier ...

Quote:

Originally Posted by Stryke (Post 1389244)
Nice. Thanks!

One question: Is there a way to delete an array?

this.array.clear();

Generally I do this:

PHP Code:

this.array.clear();
this.array = null

As sometimes clear() doesn't work, for some reason.

Robin 05-06-2008 03:27 AM

PHP Code:

obj.clear() // wont delete the array but will empty it. 

Plus, the wiki is your friend. Use it. At least until my thing comes up.

EDIT: Lol three answers at once ;)

cbk1994 05-06-2008 03:48 AM

Haha, we all posted within the same 60 seconds or so.

I've had problems with array.clear() where it will clear things, but then when you add something back, everything will be back (including what you cleared).

Programmer 05-06-2008 05:26 AM

Quote:

Originally Posted by cbkbud (Post 1389246)
EDIT: You beat me to it, Ian! If I'd have posted 30 seconds earlier ...

>: )

Robin 05-06-2008 08:04 AM

Quote:

Originally Posted by cbkbud (Post 1389257)
Haha, we all posted within the same 60 seconds or so.

I've had problems with array.clear() where it will clear things, but then when you add something back, everything will be back (including what you cleared).

Only ever used it once, but it's probably good to be wary of it.


All times are GMT +2. The time now is 01:58 PM.

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