How to send event to specific object?


#1

Ive started to do some simple game using only logic nodes (as Im not familiar yet with haxe scripting).
Im curious how to execute logic nodes tree on specific object (if I have few of of them with the same Armory trait).
When I send global event then I run code on all of them. Maybe we need kind of “Send event” node with additional “Object” slote - to point the only one exact object.
Or maybe there is anoter way to achieve this?..


#2

Maybe you can use “Get-” and “Set Property” nodes with a boolean (in the Value input) as a replacement for the event, and the properties’ object being the object you want to do stuff. “Set Property” would then be used as “Send Event” and “Get Property” (with the object being “Self”) as “On Event”.


#3

Something like that?


#4

Think so, but maybe this doesn’t works because Cube.004 asks for the value for a property that may not exist yet, and if it does not exist I think the preview will crash. Maybe you have to place a “Set Property” node with the bool being set to false and that is activated by “On Init”, and if even this crashes you will have to put a sleep node after “On Update” in Cube.004. Not sure tho, can’t test right now.
If it crashes, which it may not, so it should probably work.


#5

Thanks a lot for your answer! I will check it.
Anyway if I will not find it comfortable I will propose node modification on Github issues. Just this:

just


#6

Maybe if can help you :
if you define a name for your event and then associate the according On Event to your object,
that can play.

image


#7

@ Didier
Yes, thats how it works in simple situation (inside one trait, or when you use global event that is sended to all traits which have “On Event” with “Toto”), its clear.

I was just wondering how to reuse the same trait on few objects, but run code only on selected one in specific moment.
So to have this posibility:

One Armory trait with bunch of functions (node trees) inside. Every function is started by On Event node, with single name.

I put for example 10 objects with this trait.

Than from any node tree in game I want to start one event for only one of this 10 objects.


#8

I remember doing a test on a solution that might come close… if I remember well, it was by first coding the event name with the “event name-the object name” for which it is intended …


#9

Finally, after some tries I coded Send Event To Object Node (tweaked regular Send Event Node).
I dont know if its ideal but it works for me :smiley:
So if someone needs there is haxe file for this node
SendEventToObjectNode.hx (569 Bytes)

and code to construct node sockets for
blender.py is:

from bpy.types import Node
from arm.logicnode.arm_nodes import *
import arm.nodes_logic

class SendEventToObjectNode(Node, ArmLogicTreeNode):
    '''Test node'''
    bl_idname = 'LNSendEventToObjectNode'
    bl_label = 'Send Event To Object'
    bl_icon = 'GAME'

    def init(self, context):
        self.inputs.new('ArmNodeSocketAction', 'In')
        self.inputs.new('ArmNodeSocketObject', 'Object')
        self.inputs.new('NodeSocketString', 'Event')
        self.outputs.new('ArmNodeSocketAction', 'Out')

def register():
    # Add custom nodes
    add_node(SendEventToObjectNode, category='Action')
    # Register newly added nodes
    arm.nodes_logic.register_nodes()

The rest information - where to put this things are in "dev_logicnode’ example on github