Hi every one.
I can get a list of bodies recieved and everything, but blender won’t let me assign the one I want to a variable. It just says ‘CListObject’ is not callable. How can I assign the body value to a variable and not get this error, ie, have it work? Here is the script I have written so far. If you want the .blend let me know and I will post it.
cont = GameLogic.getCurrentController()
own = cont.getOwner()
gold = own.Gold
First, you’re mixing in some deprecated code here in the beginning
own = cont.owner
gold = own['Gold']
The error is because bodies is not a function but an attribute
gainList = earnGold.bodies
The next line doesn’t make much sense for me but I assume you most likely want to read the body value into an integer variable.
The important thing here is to check that the right message sensor is positive so there are message bodies in body list or you’ll end up accessing empty list index when sensor sends negative pulse. Also bodies are strings which you need to convert into integers.
if earnGold.positive:
gain = int(earnGold.bodies[0])
<i># do something #</i>
Thanks alot! That really helped me. @supersocks, I used your line of code, and it works perfectly, but my troubles are not over…
I posted that post late last night when I was tired. I forgot to say that I wanted to take the ‘gain’ variable and assign it to the value of a property actuator to adjust the value of the object’s property. I was doing it like this;
earnGold.setValue(gain)
Doesn’t seem to work? Is there another way to directly adjust the property value of the object without using a property actuator? @Monster, thank you for the S2A library, I am trying to figure out how to use it though… I am a really raw noobie at programing.