Lloyd Logan Posted January 12, 2014 Posted January 12, 2014 When someone enters a marker, you would use onMarkerHit(themarkertheyentered) But if I have many markers, how can I use this so that if they enter any of these markers, one event is triggered (onMarkerHit)
xXMADEXx Posted January 12, 2014 Posted January 12, 2014 addEventHandler ( "onMarkerHit", root, function ( p ) -- code end )
csiguusz Posted January 12, 2014 Posted January 12, 2014 Create a dummy element with createElement and set this elemenet as parent of your markers with setElementParent. Then define your onMarkerHit event handler attached to the dummy element.
Lloyd Logan Posted January 12, 2014 Author Posted January 12, 2014 Create a dummy element with createElement and set this elemenet as parent of your markers with setElementParent. Then define your onMarkerHit event handler attached to the dummy element. Dummy element has to be a real element, or can be made up?
Lloyd Logan Posted January 12, 2014 Author Posted January 12, 2014 Create a dummy element with createElement and set this elemenet as parent of your markers with setElementParent. Then define your onMarkerHit event handler attached to the dummy element. Dummy element has to be a real element, or can be made up? EDIT: Nevermind, I understand now thanks!
csiguusz Posted January 12, 2014 Posted January 12, 2014 Read the wiki page. What you make with that function won't be a real entity in the world, it will youst behave like an element. Eg.: local marker1, marker2 = createMarker ( ... ), createMarker ( ... ) local ele = createElement ( "markers" ) setElementParent ( marker1, ele ) setElementParent ( marker2, ele ) addEventHandler ( "onMarkerHit", ele, function () outputChatBox ( "hit" ) end ) Edit: Great! You are welcome.
Lloyd Logan Posted January 12, 2014 Author Posted January 12, 2014 Read the wiki page. What you make with that function won't be a real entity in the world, it will youst behave like an element. Eg.: local marker1, marker2 = createMarker ( ... ), createMarker ( ... ) local ele = createElement ( "markers" ) setElementParent ( marker1, ele ) setElementParent ( marker2, ele ) addEventHandler ( "onMarkerHit", ele, function () outputChatBox ( "hit" ) end ) Edit: Great! You are welcome. I have quite a number of markers, is there any easier way of doing local marker1, marker2 = createMarker ( ... ), createMarker ( ... ) local ele = createElement ( "markers" ) setElementParent ( marker1, ele ) setElementParent ( marker2, ele )
csiguusz Posted January 13, 2014 Posted January 13, 2014 A loop? local markers = { createMarker ( ... ), createMarker ( ... ), createMarker ( ... ) } for i, v in ipairs ( markers ) do setElementParent ( v, ele ) end
Lloyd Logan Posted January 13, 2014 Author Posted January 13, 2014 A loop? local markers = { createMarker ( ... ), createMarker ( ... ), createMarker ( ... ) } for i, v in ipairs ( markers ) do setElementParent ( v, ele ) end Thank you! A quick question, what does; for i, v in ipairs ( markers ) do mean?
Castillo Posted January 13, 2014 Posted January 13, 2014 It's a loop. http://lua-users.org/wiki/ForTutorial
Lloyd Logan Posted January 13, 2014 Author Posted January 13, 2014 It's a loop.http://lua-users.org/wiki/ForTutorial I'll check that out
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now