Reference before assignment : <p>Ive come across an error which i have tried tackling for a while now.</p>

<pre><code>        if outerball.pos.x &gt;= (self.r - 0.1):
            if self.rotations == 0:
                stopt = time.time ( )
                onerot = stopt - startt
                print(onerot)
            self.rotations += 1

        # update variable outputs
        timey.text = "time: %1.f" % onerot + " seconds"
</code></pre>

<p>error is <code>timey.text = "time: %1.f" % onerot + " seconds"
UnboundLocalError: local variable 'onerot' referenced before assignment</code></p>

<p>Ive tried globalizing the variable but it still hasnt made a difference.
Can someone pls explain how i can fix this.</p>

<p>Thanks</p>
