Jump to content

Element explanation request


GhostXoP

Recommended Posts

Is there any links that explain very well the idea and how to use getRootElement() and the event system. How it restricts to one type to trigger an event. Can someone give me an example as to why getRootElement() was used for example for an addEventHandler() situation

Link to comment

ok,

Root(getRootElement()) is all the elements in the server (basically)

but if you put it in a addEventHandler() client-sided then it would only apply for the localPlayer or the player viewing what ever they're viewing,

but if it's added server-sided then it means all the elements, but if the elements are created by the server then those would receive what's happening in the addEventHandler.

Link to comment

nah,

you have to put an event first then attach it to a player(if it's client-sided then it's automatically localplayer, but you should still put root) after you attach it to the player then the function comes in, this is where you're going to start the script.

Link to comment

addEventHandler

Root

Element tree

Anything you put as the second argument in triggerEvent is the source that you find in addEventHandler.

The second argument of addEventHandler LIMITS the source and gives you specifics.

For example:

For all markers, including "supermarker"

  
local supermarker = createMarker(0,0,0) 
addEventHandler("onColShapeHit", root, function() 
         outputChatBox("hit a marker") 
    end 
) 

Different message for supermarker

  
local supermarker = createMarker(0,0,0) 
addEventHandler("onColShapeHit", root, function() 
         if source == supermarker then 
             outputChatBox("hit supermarker") 
         end 
         outputChatBox("hit a marker") 
    end 
) 

Only for supermarker:

  
local supermarker = createMarker(0,0,0) 
addEventHandler("onColShapeHit", supermarker, function() 
         outputChatBox("supermarker hit") 
    end 
) 

Only tells the player that he hit the supermarker, in the dimension he is in:

  
local supermarker = createMarker(0,0,0) 
addEventHandler("onColShapeHit", supermarker, function(p,d) 
         if (getElementType(p)~="player") or (not d) then return end 
         outputChatBox("you hit the supermarker", p) 
    end 
) 

Link to comment

So its basically,

run this function if This event triggered, and only if it was triggered by this element or any children of this element, then run this function ().

In your case, if we chose root, it would trigger if any marker was hit, if we specify the specific marker, it will only run if the event was triggered by that marker. Starting to make alot of sense now. If im right, thank you very much

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...