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-18-2007, 08:52 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
item database query

so, I have made an item database, however I don't know how to do it now. Here's how it works so far

It creates an arc file, and adds the contents of that arc file to a database.
HTML Code:
1003.AmmoLimit=9999
1003.AmmoName=Uzi
1003.BulletGani=era_uzireload
1003.BulletsFire=1
1003.BulletsReduce=1
1003.ClipAmount=32
[Yes, on it's own line]
However, would this cause any lag? I can simply do from another NPC

HTML Code:
[Control].id.AmmoLimit
to return 9999

However, I could also make each item have it's own line, to control that data. However, each time I would want to check something, I'd need to look inside the array

Here's what I mean

HTML Code:
1003 = { {"AmmoLimit", 9999}, {"AmmoName", "Uzi"}, {"ClipAmount", 32}};
To gain the ammo name, I'd end up doing

HTML Code:
getData(id, name) {
  for (temp.i: this.(@ temp.id) {
    if (temp.i[0] == temp.name) {
      return temp.i[1];
    }
  }
}
What do you think would be better for the server?
__________________
Reply With Quote
  #2  
Old 10-19-2007, 12:13 AM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
I always find txt files (or whatever you want to call them) to be safer and thus better. The lag from loadlines and such would just be HD lag which Graal usually never experiances on the NPCServer so I really wouldn't worry about it. If you were to store all your data in a DB npc, not only do you have to worry about some idiot reseting the npc, but if the npcserver ever goes down, your data in those npcs might rollback.
__________________
Do it with a DON!
Reply With Quote
  #3  
Old 10-19-2007, 02:11 AM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Ew @ variable-names as pure numbers. It's not compatible in most languages... It might work on Graal though. VERY bad habit to pick up... Better leave it where you found it. On the other hand... mud_[id] would be a better variable name. Otherwise, it's alright.

I would advise you to make a function to obtain the variables through a function ( So some wise-person doesn't just go and change them ). By pretending they are protected information, you would define a function such as this:
public function "getMudProp( mudID, prop ) return this.(@ mudID ).(@ propName );

This would prevent people from knowing where the data is... It would also provide an interface to work with. The benefits of this method is that when you change the internal workings of the item, the integrity of the server remains safe ( you modify the code in one place ). It also gives you some assurance you won't mistakenly change the data. It also permits you to debug it much more effectively later on... Or do some testing on it ( efficiency-wise ). It also gives you a concise abstract 'contract' with the DB-NPC: You know, just by the function name, what are you getting exactly.

EDIT:
I don't know the difference in speed between the both methods, but as stated above, do use a function.
Reply With Quote
  #4  
Old 10-19-2007, 02:31 AM
Googi Googi is offline
A Serious Epidemic
Googi's Avatar
Join Date: Oct 2001
Location: Canada
Posts: 18,866
Googi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud of
Send a message via AIM to Googi
If you really want to know, test both methods by using a timeout. Have a script start a timeout, do some stuff (probably quite a bit of stuff) using the first method, and then save the value of the timeout to a variable/echo it/whatever. Then do the same with the second method (of course, make sure that the stuff done with the second method is the same as for the first).
__________________
Reply With Quote
  #5  
Old 10-19-2007, 03:59 AM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Quote:
Originally Posted by Googi View Post
If you really want to know, test both methods by using a timeout. Have a script start a timeout, do some stuff (probably quite a bit of stuff) using the first method, and then save the value of the timeout to a variable/echo it/whatever. Then do the same with the second method (of course, make sure that the stuff done with the second method is the same as for the first).
Directly accessing the value is systematically faster than accessing the value and comparing a bunch of values inside. ( It could be slower on loading up, but once loaded, it is fairly fast ).
Reply With Quote
  #6  
Old 10-19-2007, 05:17 AM
Googi Googi is offline
A Serious Epidemic
Googi's Avatar
Join Date: Oct 2001
Location: Canada
Posts: 18,866
Googi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud of
Send a message via AIM to Googi
Quote:
Originally Posted by Novo View Post
Directly accessing the value is systematically faster than accessing the value and comparing a bunch of values inside. ( It could be slower on loading up, but once loaded, it is fairly fast ).
But you could find out how much faster.
__________________
Reply With Quote
  #7  
Old 10-19-2007, 06:51 AM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Quote:
Originally Posted by Googi View Post
But you could find out how much faster.
N times faster. N being the size of the array.
Reply With Quote
  #8  
Old 10-19-2007, 07:03 AM
Googi Googi is offline
A Serious Epidemic
Googi's Avatar
Join Date: Oct 2001
Location: Canada
Posts: 18,866
Googi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud of
Send a message via AIM to Googi
Quote:
Originally Posted by Novo View Post
N times faster. N being the size of the array.
If you don't count the time it takes to open and read the file, sure.
__________________
Reply With Quote
  #9  
Old 10-19-2007, 07:32 AM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Quote:
Originally Posted by Googi View Post
If you don't count the time it takes to open and read the file, sure.
Which is what caching does. You read it from file, you cache it to memory. The load-up times would differ. Taking the average amount of time it took to load up over the average life-span of the variable and you'll conclude that the load-up times are inconsequential.
Reply With Quote
  #10  
Old 10-19-2007, 08:54 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Quote:
Originally Posted by Novo View Post
Ew @ variable-names as pure numbers. It's not compatible in most languages... It might work on Graal though. VERY bad habit to pick up... Better leave it where you found it. On the other hand... mud_[id] would be a better variable name. Otherwise, it's alright.

I would advise you to make a function to obtain the variables through a function ( So some wise-person doesn't just go and change them ). By pretending they are protected information, you would define a function such as this:
public function "getMudProp( mudID, prop ) return this.(@ mudID ).(@ propName );

This would prevent people from knowing where the data is... It would also provide an interface to work with. The benefits of this method is that when you change the internal workings of the item, the integrity of the server remains safe ( you modify the code in one place ). It also gives you some assurance you won't mistakenly change the data. It also permits you to debug it much more effectively later on... Or do some testing on it ( efficiency-wise ). It also gives you a concise abstract 'contract' with the DB-NPC: You know, just by the function name, what are you getting exactly.

EDIT:
I don't know the difference in speed between the both methods, but as stated above, do use a function.

Got ya, thanks.

I just thought that doing a loop serverside for each prop would cause some some problems
__________________
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 09:18 PM.


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