Hard Light Productions Forums
Off-Topic Discussion => Programming => Topic started by: Locutus of Borg on July 02, 2011, 07:38:46 am
-
Here's basically how I have it set up
I have a class called World, which has a function called somethingPicked
somethingPicked defines a variable, Position, and then sends a message to the Coin class to execute a function flipCoin
in flipCoin I need to compare the variable Position to the variable r1, which is defined in the coin class.
How do I write it so that I can use the variable position from the World class in a comparison with the variable r1 from the coin class?
-
DISCLAIMER: I do not know Python
Unless World.Position is publicly accessible, you can't. In most object-oriented languages, you need to declare it as being publicly accessible. See http://en.wikipedia.org/wiki/Object-oriented_programming for pointers.
-
I declared it as self.Position and it still didn't work
-
In Python everything is publicly accessible.
Are you passing your World instance to your flipCoin call? If you don't need anything else from World, why not just pass Position?
-
I'm not that familiar with Python. Could you please explain that? :S
I tried calling the variable World.somethingPicked.Position and that didn't work either
-
Make your flipCoin take a position:
def flipCoin(self, position):
...
and in somethingPickled
coin.flipCoin(position)
or if position is a field in World
coin.flipCoin(self.position)
-
TypeError: unbound method coinFlip() must be called with Coin instance as first argument (got int instance instead)
-
Is coin a Coin?
If you want more help, post your code.