pygame - Proper way to pass an object to a function [python] -


i'm working on shooter game in python using pygame , have question proper way pass object function.

each player in game assigned team upon joining game. there class called team keeps track of status of team (score, number of players, etc.). team objects stored in list. sometimes, function need @ and/or modify team object. i'd know of following 2 methods better way pass team object function.

method 1:

each team object has attribute integer called teamid. each teamid unique. if function needs access team object, passed teamid, search through list of teams until finds object appropriate teamid , use object.

example:

def functionthatneedsteam(teamid):     team = getteambyid(teamid)     dosomething()     return  functionthatneedsteam(teamid) 

method 2:

if function needs access team object, passed team object itself.

example:

def functionthatneedsteam(team):     dosomething()     return  functionthatneedsteam(teamobject) 

i've seen both of these methods used in various pygame projects i've looked @ , know 1 better. appreciated.

you should pass function data needs job.

does have use id? should pass parameter. otherwise, pass team, or if uses 1 attribute of team, consider passing instead.

most of time doing leads less code correct.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -