The problem is my general lack of python knowledge. I have a general idea of how to do what I want, but I don’t know the specific commands to use. I want to know how to find the property values on a few different objects and use some of them to set the others.
Here is a sample script that gives me an error with 'getProperty" not being valid.
Two cubes exist in different locations and with different rotations. They both have an integer property titled style with different numeric values. I want to use a python script to set the style of the first object to the value of the second object.
Also, where/how would I find a helpful list of commands and how to use said commands with GameLogic?
I know the code is wrong, I dont’ really know what I’m doing when it comes to Python.
It looks like you’re using documentation from v 2.46, and for the main Blender module which can’t be used in games. getProperty isn’t usable in the game engine.
Current GameLogic docs are here. If you’re using the current Blender version.
Some of those entries have examples, others not. You can do a search here at blenderartists with just the command you’re confused about to find out what it does.
All right, what you’re trying to do would look like this, I think (haven’t tested, and just concerning the property):
import GameLogic as G
src=G.getCurrentScene().getObjectList()["OBCube"]
dest=G.getCurrentScene().getObjectList()["OBCube.001"]
dest.style = src.style
myOb.setattr(‘style’, 1)
var = myOb.getattr(‘style’)
if myOb.hasattr(‘style’): …
I used this quite a bit for yo-frankie, where inventory items can be added without having to know the names of each item beforehand.
example
# Adds an attribute if its not there, otherwise increments,
# yo-frankies inventory system works this way.
attr = 'item_' + someItemName # use item prefix to ensure no name conflicts
if myOb.hasattr(attr): myOb.setattr(attr, myOb.getatter(attr) + 1)
else: myOb.setattr(attr, 1)