Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-05-2008, 03:50 AM
Stryke Stryke is offline
Scripter
Join Date: Apr 2008
Posts: 157
Stryke is an unknown quantity at this point
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)
}
}
}
Reply With Quote
  #2  
Old 05-05-2008, 03:52 AM
Programmer Programmer is offline
Coder
Programmer's Avatar
Join Date: Jan 2008
Location: -78.464422, 106.837328
Posts: 449
Programmer has a spectacular aura aboutProgrammer has a spectacular aura about
Send a message via AIM to Programmer Send a message via MSN to Programmer Send a message via Yahoo to Programmer
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!"
__________________
- Iᴀɴ Zɪᴍᴍᴇʀᴍᴀɴ
Reply With Quote
  #3  
Old 05-05-2008, 03:54 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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" };
__________________
Reply With Quote
  #4  
Old 05-05-2008, 04:47 AM
Stryke Stryke is offline
Scripter
Join Date: Apr 2008
Posts: 157
Stryke is an unknown quantity at this point
Thanks. Exactly what I need. Meh now I have to change my guild manager script to 2d guild_list arrays though.
Reply With Quote
  #5  
Old 05-05-2008, 01: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
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.
Reply With Quote
  #6  
Old 05-05-2008, 10:18 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Stefan View Post
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.
__________________
Reply With Quote
  #7  
Old 05-05-2008, 10:21 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by cbkbud View Post
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)..
__________________
Reply With Quote
  #8  
Old 05-05-2008, 10:38 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Chompy View Post
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).
__________________
Reply With Quote
  #9  
Old 05-05-2008, 10:55 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
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
Reply With Quote
  #10  
Old 05-06-2008, 02:15 AM
Stryke Stryke is offline
Scripter
Join Date: Apr 2008
Posts: 157
Stryke is an unknown quantity at this point
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);
Reply With Quote
  #11  
Old 05-06-2008, 02:35 AM
Robin Robin is offline
The secret of NIMH
Robin's Avatar
Join Date: Apr 2005
Location: Wales, UK
Posts: 515
Robin will become famous soon enough
Send a message via AIM to Robin
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) 
__________________

Reply With Quote
  #12  
Old 05-06-2008, 03:03 AM
Stryke Stryke is offline
Scripter
Join Date: Apr 2008
Posts: 157
Stryke is an unknown quantity at this point
You won't know the total list of guilds using that, and you can't add guilds.
Can someone answer my question?
Reply With Quote
  #13  
Old 05-06-2008, 03:11 AM
Robin Robin is offline
The secret of NIMH
Robin's Avatar
Join Date: Apr 2005
Location: Wales, UK
Posts: 515
Robin will become famous soon enough
Send a message via AIM to Robin
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 View Post
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 View Post
this.( @ "guild_" @ guildname ).members = { "cbkbud", "cbk1994", "Stefan" };
Quote:
Originally Posted by cbkbud View Post
this.( @ "guild_" @ guildname )
Quote:
Originally Posted by cbkbud View Post
this.( @ "guild_" @ guildname )
__________________

Reply With Quote
  #14  
Old 05-06-2008, 03:22 AM
Stryke Stryke is offline
Scripter
Join Date: Apr 2008
Posts: 157
Stryke is an unknown quantity at this point
Nice. Thanks!

One question: Is there a way to delete an array?
Reply With Quote
  #15  
Old 05-06-2008, 03:26 AM
Programmer Programmer is offline
Coder
Programmer's Avatar
Join Date: Jan 2008
Location: -78.464422, 106.837328
Posts: 449
Programmer has a spectacular aura aboutProgrammer has a spectacular aura about
Send a message via AIM to Programmer Send a message via MSN to Programmer Send a message via Yahoo to Programmer
Quote:
Originally Posted by Stryke View Post
Nice. Thanks!

One question: Is there a way to delete an array?
temp.array = null;
__________________
- Iᴀɴ Zɪᴍᴍᴇʀᴍᴀɴ
Reply With Quote
  #16  
Old 05-06-2008, 03:27 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
EDIT: You beat me to it, Ian! If I'd have posted 30 seconds earlier ...

Quote:
Originally Posted by Stryke View Post
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.
__________________

Last edited by cbk1994; 05-06-2008 at 03:48 AM..
Reply With Quote
  #17  
Old 05-06-2008, 03:27 AM
Robin Robin is offline
The secret of NIMH
Robin's Avatar
Join Date: Apr 2005
Location: Wales, UK
Posts: 515
Robin will become famous soon enough
Send a message via AIM to Robin
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
__________________

Reply With Quote
  #18  
Old 05-06-2008, 03:48 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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).
__________________
Reply With Quote
  #19  
Old 05-06-2008, 05:26 AM
Programmer Programmer is offline
Coder
Programmer's Avatar
Join Date: Jan 2008
Location: -78.464422, 106.837328
Posts: 449
Programmer has a spectacular aura aboutProgrammer has a spectacular aura about
Send a message via AIM to Programmer Send a message via MSN to Programmer Send a message via Yahoo to Programmer
Quote:
Originally Posted by cbkbud View Post
EDIT: You beat me to it, Ian! If I'd have posted 30 seconds earlier ...
>: )
__________________
- Iᴀɴ Zɪᴍᴍᴇʀᴍᴀɴ
Reply With Quote
  #20  
Old 05-06-2008, 08:04 AM
Robin Robin is offline
The secret of NIMH
Robin's Avatar
Join Date: Apr 2005
Location: Wales, UK
Posts: 515
Robin will become famous soon enough
Send a message via AIM to Robin
Quote:
Originally Posted by cbkbud View Post
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.
__________________

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 06:45 PM.


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