You need to convert this property from integer form, into string form.
A good way to do this is the repr() built in function.
The code below should fix your problems.
cont = GameLogic.getCurrentController()
addobj = cont.getActuator("addobj")
prop = cont.getSensor("prop")
propvalue = prop.getValue()
if propvalue<29():
objname = repr(propvalue) # This line is added.
addobj.setObject(objname) # This line is modified.
GameLogic.addActiveActuator(addobj, 1)
Edit: Also, I feel like I should add that there is an easier way of getting and manipulating a property.
con = GameLogic.getCurrentController()
own = con.getOwner() # This is the object that the controller is on.
# A property named "myProp" can be accessed
# as own.myProp, as shown below
own.myProp = 8 # setting myProp to 8
print own.myProp # printing out the property.
ya. i don’t think i was really thinking straight when i started this. i swapped out the property sensor for own.prop in the script. whatever. i fixed that and it’s working fine now
There is how I would write the script, I moved the addobj = cont.getActuator(“addobj”) line after the if: because if the property is over 29 it will just be a waste of getting the actuator and storing it in a variable so it will have a small (unnoticible) performance increase but if you have enough of those unnoticible increases they will become noticible
And you can use the str() function to turn an int or a float into a string, same as there is an int() function to turn a float or a string into an int and there is also a float() function, guess what that does.
Replace own.propertyname with whatever the name of the property is and with this there is no reason to even get the sensor so that will be another small performance increase.
I’m not sure wether repr() or str() is faster but str() seems more widely used.
I hope some if this helped even if this question was already answered…
I believe repr is faster then str, because str checks if the given data is already a string. repr on the other hand, will “string-ify” a string if you tell it to.
For example:
word = "hello"
print str(word)
print repr(word)
### OUTPUT ###
hello
'hello'
As you can see, repr will add quotations to a string, whereas str will not.