Greetings fellas. I want to change a property of an object based on another’s. E.i.: Object A has a text property to display text. Objects B, C, D have individual properties. I want to use a ray detection so that if the camera is pointing at objects with properties, a message is sent to change the text property from A. So object A will display tho other objects propeties.
If there’s another method I don’t know of, please iluminate me!
Thank you for your atention!
Hello
If I understood well, you can use the Copy Property Actuator:
Select object A, and add:
Always Sensor ( with + pulse on) -> AND -> Property Actuator - Copy - Prop: theNameOfTextPropHere - OB: ObjectBNameHer Prop: NameOfObjectBPropertyHere
Do the same for the others objects
Bye
There’s a much better method. I’ll type up the code and I’ll explain it with the notes.
Also, this is for 2.49b, to convert it to 2.5 just take out the OBs from the object name. Also, this script it put onto an object with a ray sensor called “ray” that only sensors objects with the property “copy”, object A is called “text_display”.
#Just making some variables
import GameLogic as g
cont = g.getCurrentController()
own = cont.owner
scene = g.getCurrentScene()
objects = scene.objects
ray = cont.sensors["ray"] #sensor
obA = objects["OBtext_display"] #The display object
if ray.positive: #If the ray senses an object
object = ray.hitObject #This could be object A, B or C, with the property.
obA["Text"] = str(object["copy"]) #the property copy on the object the ray just hit is put on Text as a string
And that’s it!
If you want I can make a quick example with just the debug properties
Thanks a lot guys, you both gave me new insight! However, this is not fulfilling my needs (I don’t mean to sound selfish here…). For the first reply, OTO, I’ll have hundreds of objects with dynamically generated property values (actually, it will be the string addiction of their coordinates) and I can’t possibly do it manually.
As for the second, reply by Likxgl, I need the value of the property to fill up the Text value, I hope that by: str(object[“copy”]), you mean the string value and not the property name!
I’ll test it and see what come out!
Thank you so very much!
I’m sorry for being so prompt to assume things, it works perfectly!
I’d like to ask another easy script.
Objects B, C, D have 5 properties :
1- xloc: int given by the owner worldPosition
2- yloc: int idem
3- zloc: int idem
4- name str
5- copy str
Now, ‘copy’ = str(Name+xloc+yloc+zloc)
So the script must check for all objects having the ‘name’ property and do the operation.
Once again thank you!
hmmm… I think that’s pretty easy, just change the property in the ray sensor to name
I don’t really understand what you need though, but I don’t think it’ll matter if you check for which ever property. If all the objects that you want to sense have all those properties, why would you need it to sense a certain one?
Still you can just change it to name, to make it more recognizable
The name property is the one I’m asking to help me change! So the name value will be a composite of the previous properties, omething like ‘NameA023065’. Being 02.30.65 the object’s worldPosition.
I’m trying to individualize objects since I’m going to use instances of the same objects in the same scene!
I would use:
scn = GameLogic.getCurrentScene()
ob = scn.objects
obl = [ob for ob in scn.objects if ob.has_key(“whatever”)]
for ob in obl:
seed = str(int(GameLogic.getRandomFloat() * 100000000))
ob[“whatever”] = “name” + seed
That way you can have one script that runs through a list of many objects and changes their properties. This would give you a name plus a string of random numbers, there is a small chance that two objects could get the same seed, but not too likley I think you’ll agree.
Yes, I see! Thank you, I’ll use the random later on, but I really need to know where the objects are, for debug and test reasons that’s why I wanted it to be coordinates instead of a random number!
Then, when you do the (for ob in obl) you can call up each object’s co-ordinates and add them as a string.
ex.
ob[‘whatever’] = “name” + str(ob.worldPosition)
you can use other string manupulation to reformat the data in to a set of numbers.
A good tutorial is here:
Thanks smoking mirror, I’ll give it a shot!