Re: Python, passing objects?

The given example only covers initialization, which only happens once when the object is created. In the case of an update loop that requires an object every loop, it depends on how you setup the update function to handle the data, or lack thereof, thats sent to it. For example:

class example(object):
     def update(self,data):
         if data != None:
             print(data)

In this example, you can pass update either a data object or None, but you always have to pass it something. But another way to handle it is to set the local variables default like so:

class example(object):
     def update(self,data=""
         if data != None:
             print(data)

What this does is make it so if you pass example a variable, such as "example(thing)", then "thing" will overwrite the local data variable in update so it becomes "thing". Now if you don't pass it anything, such as "example()", then the local data variable in update will default to None automatically.



-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : nyanchan via Audiogames-reflector

Reply via email to