Announcement

Collapse
No announcement yet.

Error in Python Guide on modiki

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error in Python Guide on modiki

    In part 4 (Python in CIV) of the python guide on the modiki, I think there is an error. It says that if you use
    Code:
    Damage = CyGlobalContext().getPlayer(1).getUnit(0).getDamage()
    then every time you say "Damage" afterwards it will make the entire long function call.

    As far as I can tell, this is not true. If you were to run this assignment statement, then change the damage of the unit, then check the value of Damage, it would not have updated. This is because the variable damage is storing the return value of the function (OK, if you want to get technical, it's storing a reference to the return value of the function.) If you wanted to make Damage a reference to the function, you could write this:
    Code:
    Damage = CyGlobalContext().getPlayer(1).getUnit(0).getDamage
    Notice that there are no parentheses after getDamage. To use it you would write "Damage()" which would actually call the method and return the value.

    Here is what I did in a python console to verify this:
    Code:
    >>> class test:
    	def __init__(self):
    		self.x = 0
    	def getX(self):
    		return self.x
    
    	
    >>> t = test()
    >>> t.x
    0
    >>> t.getX()
    0
    >>> x = t.getX()
    >>> x
    0
    >>> t.x = 1
    >>> x
    0
    >>> x = t.getX
    >>> x
    >
    >>> x()
    1
    >>> t.x = 2
    >>> x()
    2
    Of course this is a wiki so anyone can go in and fix this. But I didn't want to make important changes to someone else's guide without getting feedback on it.

    Thanks,
    Daniel

  • #2
    sounds reasonable. When writing a guide it's almst impossible to avoid all errors. Go ahead and edit it. Sice you have tested your change it should be ok.
    Creator of the Civ3MultiTool

    Comment

    Working...
    X