You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you use Python dictionaries (the equivalent of HashMaps in Java) to keep track of Tophat traits in Tophat.py then it might be a clearer way to grab the side and direction than pulling from an array.
Second, if you change the static variable all_tophats from an array into a dictionary, then you would be able to reference tophats by their names. The calling syntax could look something like this:
Old:
all_tophats[0]
New:
all_tophats["left"]
Dictionaries work by mapping one piece of data to another in "key-value pairs." It's a little bit like magic but bear with me. In this case, we could automatically link an object's name to anything we want. Right now, we just append self to the next array slot in all_tophats. This can be nice to count the number of total tophats, but makes finding the exact one you want a pain because you don't know which number is associated with which tophat. Instead, we could put the same data self into a dictionary so that it is mapped to the string representing its name. Essentially, you would then be able to search for the tophat you want by its name.
The text was updated successfully, but these errors were encountered:
If you use Python dictionaries (the equivalent of HashMaps in Java) to keep track of Tophat traits in
Tophat.py
then it might be a clearer way to grab the side and direction than pulling from an array.Theoretically, you could do something like
Old:
Incredibots2020/Legobot/Tophat.py
Lines 21 to 22 in eb87e14
New:
Second, if you change the static variable
all_tophats
from an array into a dictionary, then you would be able to reference tophats by their names. The calling syntax could look something like this:Old:
New:
Dictionaries work by mapping one piece of data to another in "key-value pairs." It's a little bit like magic but bear with me. In this case, we could automatically link an object's name to anything we want. Right now, we just append
self
to the next array slot inall_tophats
. This can be nice to count the number of total tophats, but makes finding the exact one you want a pain because you don't know which number is associated with which tophat. Instead, we could put the same dataself
into a dictionary so that it is mapped to the string representing its name. Essentially, you would then be able to search for the tophat you want by its name.The text was updated successfully, but these errors were encountered: