event node

Summary

The event node groups action nodes and only actions them once the event has been triggered. Otherwise, the event node behaves in the same way as the concurrent node.

For more information see the XML reference entry for event.

Constructor

event.new( [id] )

The parameter id is optional. If specified the node will be given this id.

Example C.6. Use of event constructor

<scene>
	<script type="text/x-lua">

		-- create a new event node
		myevent = event.new()
		
		-- OMITTED create and add actions to the event node
		
		scene:appendNode(myevent)
		
		-- the event (and its child actions) are now in the scene
		-- and will occur when the event is triggered
		
	</script>
	
</scene>

Functions

node:setProximityNode( object )

In the case that this node is the onproximity event for an object, setProximityNode indicates the other node that will be checked for proximity to the parent object of this node. For more information see Reacting to object proximity.

Example C.7. Use of setProximityNode

<scene>
	<script type="text/x-lua">

		mybullet = scene:getById("mybullet")
		mytarget = scene:getById("mytarget")
		
		targetCollision = event.new()
		-- OMITTED add actions to targetCollision event

		targetCollision:setProximityNode(mybullet)
		targetCollision:setProximityThreshold(0.1)
		
		mytarget:setEvent("onproximity", targetCollision)
		
	</script>
		
	<object id="mybullet" ... />
	<object id="mytarget" .../>
	
</scene>


node:setProximityThreshold( threshold )

In the case that this node is the onproximity event for an object, setProximityThreshold indicates how close the centers of the parent object and the other object must be for the event to be triggered. For more information see Reacting to object proximity.

Example C.8. Use of setProximityThreshold

<scene>
	<script type="text/x-lua">

		mybullet = scene:getById("mybullet")
		mytarget = scene:getById("mytarget")
		
		targetCollision = event.new()
		-- OMITTED add actions to targetCollision event

		targetCollision:setProximityNode(mybullet)
		targetCollision:setProximityThreshold(0.1)
		
		mytarget:setEvent("onproximity", targetCollision)
		
	</script>
		
	<object id="mybullet" ... />
	<object id="mytarget" .../>
	
</scene>


node:trigger()

Triggers the node to start performing its child actions.

Example C.9. Use of trigger

<scene>
	<script type="text/x-lua">

		myevent = scene:getById("myevent")
		
		myevent:trigger()
		
	</script>
		
	<event id="myevent">
		<!-- OMITTED add actions -->
	</event>
	
</scene>


Functions common to nodes that group actions

node:appendAction( action_node )

Adds the passed node as a child of this action node.

Example C.10. Use of appendAction

<scene>
	<script type="text/x-lua">
		
		myconcurrent = scene:getById("myconcurrent")
		
		mytransition = transition.new(...)
		-- OMITTED set up transition
		
		myconcurrent:appendAction(mytransition)
		
	</script>
	
	<concurrent id="myconcurrent">
		<!-- transition will be added here by script -->
	</concurrent>
	
</scene>


Functions common to action nodes

node:reset()

Resets this action such that it will occur again (from the beginning).

node:setNoTimes( val )

Sets the number of times this action should occur. Pass the value -1 to repeat indefinitely.

Example C.11. Use of setNoTimes

<scene>
	<script type="text/x-lua">
		
		mytransition = scene:getById("mytransition")
		
		mytransition:setNoTimes(10)
		
	</script>
	
	<transition id="mytransition"
				object="myplane" 
				what="position" 
				start="0 0 0" end="1 1 1" 
				length="1000 />

	<object id="myplane" type="primitives://plane.aro"/>
	
</scene>


Functions common to nodes

col graphnode:getColor()

Returns a table of 4 values - red, green, blue and alpha (transparency) between 0.0 and 1.0.

Example C.12. Use of getColor

<scene>
	<script type="text/x-lua">
		
		myplane = scene:getById("myplane")
		cols = myplace:getColor()
		red = cols[1]
		green = cols[2]
		blue = cols[3]
		alpha = cols[4]
		
	</script>
	<object id="myplane" type="primitives://plane.aro" color="0.5 1 1 0.75"/>
</scene>


boolean graphnode:isVisible()

Returns true if the node is set to visible, or false otherwise.

graphnode:setColor( col )

Sets the color of the node. Pass a 4-element table with entries { red, green, blue, alpha }. Values are expressed between 0.0 and 1.0.

Example C.13. Use of setColor

<scene>
	<script type="text/x-lua">
		
		myplane = scene:getById("myplane")
		
		--         r    g   b    a
		newcol = { 0.1, 1, 0.5, 0.25 } 
		myplane:setColor(newcol)
		
	</script>
	<object id="myplane" type="primitives://plane.aro"/>
</scene>


graphnode:setVisible( true or false )

Sets the visibility of the node. Invisible nodes are not displayed and do not respond to events e.g. onhover, onclickdown etc.