When writting an equipping methods that uses an associative list to keep track of what is equipped, is it better to:
Reference the list every time a value of a variable is needed from the item.
or
Copy the values of the variables to variables owned by the mob when the item is equipped. Then reference the mobs variables.
I have done it both ways, I think the first way would be more accurate and safer, but the second way would be faster getting the values of the variables. Any opinions?
ID:152358
Feb 24 2007, 11:49 am (Edited on Feb 26 2007, 7:46 pm)
|
|
In response to Crispy
|
|
Crispy wrote:
"Safe" beats "needlessly optimised" any day. Unless it's this day, where Top Gear converted a 3-wheeler Robin Reliant into a space shuttle, strapped it to a rocket and sent it into space. If that's not the essence of "needlessly optimised" (and also the antithesis of safe) then I don't know what is. |
for the second method, it depends on what values you may have to copy over. several different items might increase the same stat, in which case it would be advantageous to copy them all over to the mob's variable. for example, if several pieces of equipment give you armor, to find your total armor value it would be easier to keep track of the mob's total armor as equipment changes.
the second method is only unsafe if you implement it poorly. but, if you're going to implement things poorly then the first method could be unsafe too. |
In response to OneFishDown
|
|
I usually do,
mob I store all equipment in a seperate list from the contents, I am not sure if thats the best idea, but it works fine for me. |
In response to Elation
|
|
Oh yeah. Shame about the big hole it made when it hit the ground.
My method with regards to equipment is similar to Dark Wizard's, with an associative array and a variable or two for short access to certain objects (mainly the player's weapon). |
I don't know the all the details but I would've assumed an associative list in DM is simply an object that can have variables added to it at runtime so there's no real speed difference between accessing a variable in an associative list and a normal variable.
Also, let's face it, we're talking about DM here. Even if there were differences in speeds of two different methods the more accurate and safer option would be the best.