I’m working on a Minecraft type clone in Blender. Click on that minecraft link or here if you don’t know what Minecraft is.
I already tried adding logic on the ground cubes:
Mouse Over Edit Object: Delete
+ ----------AND--------
Mouse Left Click (TAP)
But I want to have the deleting “mechanism” inside the player instead of the individual cubes. So how do I delete an object without having the logic in it? I found this code and I thought I could use it for this need:
def main():
cont = GameLogic.getCurrentController()
own = cont.owner
sens = cont.sensors['hit']
if own.init == 0:
own.init = 1
if sens.positive:
sens.hitObject.endObject()
main()
I edited the original code that I found from someone else so I’m not sure how important the “if own.init==0, own.init = 1” part is. But my objective was to have this code check if the object my mouse was over and left clicking had a property of “ground”. If it had that property it would delete said object, if it didn’t have that property nothing would happen.
Input: Mouse must be over object, object must have property “ground” (or custom name), and left click must be positive. Outcome: delete object that mouse was over.
Any ideas?
I’ll post the original .blend file that has the original code in it from the thread I found it in.
it was made by jplur, i think i got the name right.
attached files:
blendcraft - the one i’m trying to do this upgrade on
inventory - as listed above
deletecube.png - current logic set up on individual sandbox cubes
Hi,
I understand what this script does. I’ll rephrase what I meant earlier.
If by using this script you showed here, is it possible to check if the object I am clicking on has a certain property at a certain value? Such as “prop: ground…value: 0”, and if it is true that the object being clicked has this property at the specific value, to delete the hit object?
This would prevent the player from accidentally deleting objects without the property. If possible, would it be able to search for just the property name without requiring a value such as 0? (just searching the hit object for a specified property name)
import GameLogic
cont = GameLogic.getCurrentController()
own = cont.owner
# the property that the object must have
PROP = 'Prop' # Change to own['PropName'] to assign to a prop on this object
# the value that property must be at
VALUE = 1 # Change to own['PropName'] to assign to a prop on this object
mouse = cont.sensors["mouse"]
click = cont.sensors["click"]
if mouse.positive and click.positive:
if not PROP or (mouse.hitObject.has_key(PROP) and mouse.hitObject[PROP] == VALUE):
mouse.hitObject.endObject()
Leave prop as None to delete all objects under the mouse.
-Sunjay03