Hello, first, sorry for my english, im french.
Im making my own minecraft game, but i have a issue with my script, i started python scripting 2 weeks ago and i need your help.
I explain me:
I have a “lastblock” string property on my Camera, and when i look at a block, and i leftclick on mouse, the “lastblock” property take the name of the looked object (Exemple: Bloc-Grass).
But i want if you look another object, or the sky or anything… the last object name in the property “lastblock” , i want my script take his name and set his own “Default” property to his own “Solidite” property. after that, the “lastblock” property can be set to nothing.
I just want make this:
lastblock = se.objects[the string value in “lastblock” property/the block name in my “lastblock” prop]
i try with different way but nothing work.
I paste you the script (i use # for show you what i want):
cible = Ray.hitObject
if own[‘lastblock’] != cible:
print("!= cible")
proplastblock = own[“lastblock”]
print(proplastblock) #lastblock = se.objects… #HERE IS MY PROBLEM #lastblock[“Solidite”] = lastblock[“Default”] #degats.visible = 0 #own[‘lastblock’] = “”
However, if the blocks are instanced (using addObject / the add object actuator), then you can’t use names, because they’re not unique.
Instead, you can store the block object reference in the game property, rather than its name, or you can store its Python ID, and use scene.objects.from_id(SOME_ID) to retrieve it.
The name of my objects are “Bloc-Grass” or “Bloc-Sand”… it is ok or i have to change their name?
I think i have tu use your second method because all the blocs are edited (terrain generator, when player put a bloc…).
I have 2 other questions:
If i want to reset my string property “lastblock” (Set it empty), does this line is ok:
own[‘lastblock’] = “”
2. I made my “lastblock” property of my camera visible in the bge (you can see on the picture), but when the string property is changed, the property disappear of the Debug property.
I want do this for look what object is in my property in-game, without the python console.
I made a mistake in my code, which I’ve corrected.
The problem is that when you add objects using the actuator or Python, the added objects all have the same name, so you can’t easily find the correct object.
Instead, save the object reference itself, not its name, and use that directly.
def look_at(cont):
own = cont.owner
ray_sensor = cont.sensors['Ray']
mouse_sensor = cont.sensors['Mouse']
if not (ray_sensor.positive and mouse_sensor.positive):
return
seen_object = ray_sensor.hitObject
own['last_block'] = seen_object
Here, you can use own[‘last_block’] directly, it’s a KX_GameObject reference.