View Single Post
Old 08-10-2014, 05:51 PM   #30
Groundhog
Coordinator
 
Join Date: Dec 2003
Location: Sydney, Australia
Haven't been a lot of updates the past week because I decided I needed my first and hopefully only major re-do. The issue I had was that I'd stored all the player attributes in a list, which meant referencing them as a number value in the order they were listed.

For example, initially the player information was held as follows:
Code:
[id#, "A. Varejao", 70, 15, 14, 7, 7, 0, etc]
I had a key of what each attribute related to - offaware, 2pt, etc. And when I called the player's rating to use it in a calculation, I would reference it by the order it appears in the list - height would be 'player[2]' for example (counting starts from 0). Although it may not sound overly complicated, once the number of attributes hits the 20 mark it starts to get a bit messy, especially when I'm going back and reading code a few days later.

I wanted to change everything to dictionaries. Dictionaries are a kind of database that allows you to store a value against a key that can be used to reference that value. This makes it a lot easier to read. To use the example above:
Code:
{"name": "A. Varejao", "height": 70, "jump": 9, "offaware": 14, "defaware": 14, etc}
If I'm then passing a value to a calculation, say Varejao's heigh and jump ratings for a jump ball, I'm simply passing 'player["jump"]' and 'player'["height"]'.

Seems simple, but it meant rewriting nearly every function I had put together, which was also a good opportunity to clean up a few things using methods I'd learned since I began.
__________________
Politics, n. Strife of interests masquerading as a contest of principles.
--Ambrose Bierce
Groundhog is offline   Reply With Quote