MAB Posted February 19, 2016 Share Posted February 19, 2016 (edited) Delete Edited February 20, 2016 by Guest Link to comment
Bonus Posted February 19, 2016 Share Posted February 19, 2016 The code does: 1. Create a global variable a (why global and not local?) 2. Create the function float 3. Overwrite the function float 4. Call float with onClientRender There can't be 2 global functions with the same name. And you should really care about the performance, your code is ****. You use really bad names for global variables and functions. Example how to write the code MUCH better: local markerupspeed = 0.1 -- Use names describing the function local counttorevert = 0 -- Use local! Better performance + security local shopMarkers = {} -- Save the markers in a table, better than getElementsByType local function moveTheShopMarkes ( ) -- its called in every frame, localize it to speed up the access if counttorevert + 3000 <= getTickCount() then -- dont need for "not counttorevert" because of counttorevert = 0 markerupspeed = markerupspeed * -1 counttorevert = getTickCount() end for i=1, #shopMarkers do -- We use the table created at resource-start - its faster local x, y, z = getElementPosition ( shopMarkers[i] ) setElementPosition ( shopMarkers[i], x, y, z + markerupspeed ) end end addEventHandler ( "onClientResourceStart", resourceRoot, function ( ) local markers = getElementsByType ( "marker" ) -- save it to use for i=1, #markers local counter = 0 -- counter for integer index for i=1, #markers do -- Better than pairs or ipairs if getElementData ( markers[i], "shopMarker" ) then -- don't need "== true" if it can be only true or false counter = counter + 1 shopMarkers[counter] = markers[i] end end addEventHandler ( "onClientRender", root, moveTheShopMarkes ) end ) Link to comment
MAB Posted February 19, 2016 Author Share Posted February 19, 2016 Thanks, haven't test yet but thanks for the information. I overwrite t float function by mistake. Link to comment
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