Jump to content

onClientRender bug.


bandi94

Recommended Posts

I am creating a costum GUI theme. (rebuild it with Dx)

I made a function to animate move on X axis. All good when i call it 1 time. But when i call it 2 time's at the same time , to move 2 element's (images) at the same time , It get bugged , as far as i find it's that onClientRender it's not removed (only one of them is , every call create's one onClientRender.)

function DGTAnimateStaticImage(Element,from_x,speed) 
  
 local x = getElementData(Element,"x")  
  setElementData(Element,"animation",true) 
  setElementData(Element,"x",from_x) 
  
      move_image = function() 
  
 local x1 = getElementData(Element,"x")  
  
      if not x1 then 
        removeEventHandler('onClientRender',getRootElement(),move_image) 
      end 
  
  
     if(x1<=x) then 
        setElementData(Element,"x",x1+speed) 
     else 
      removeEventHandler('onClientRender'getRootElement(),move_image) 
      outputChatBox("removed") 
      setElementData(Element,"animation",false) 
     end 
  
  
  
end 
         
addEventHandler('onClientRender',getRootElement(),move_image)  
end 
  

Link to comment

Well i don't need to use "interpolateBetween" , my way is more easy bk i need only a linear X axe move.

I don't used table bk i wanted to save "onClientRender" (my way stop's the EventHandler when the move is completed , table mode will not stop the EventHandler bk he need to check if there is any new element in the table, so i can't stop it).

One way would be to send a tabel and call it only once. But this way will not work if i wanna a delay between the starting time's.

So i gues the table mode is only way.

Link to comment
  • Moderators

What is wrong with table mode?

What is wrong with writing directly to the ram? It can't be faster can it?

Tables can do everything, even stop things.

There is and function called: https://wiki.multitheftauto.com/wiki/IsElement

Loop through the table and when you notice the element is gone you can simply remove it from the table.

setElementData is a function a table isn't, so use local tables or data ...... they almost don't have any delays/lagg.

Link to comment
  • Moderators

This is how I script this:

local imageTable,renderImage = {},false 
  
local move_image 
move_image = function() 
    for element,data in pairs(imageTable) do 
        if isElement(element) then 
            local x1 = data.from_x 
            if(x1<=x) then 
                data.from_x = x1 + data.speed 
            else 
                imageTable[element]= nil 
            end 
        else 
            imageTable[element]= nil 
        end      
    end 
    if not next(imageTable) then 
        removeEventHandler('onClientRender',root,move_image) 
        renderImage = false 
    end 
 end 
  
function DGTAnimateStaticImage(Element,from_x,speed) 
    imageTable[Element] = {from_x = from_x,speed = speed} 
    if not renderImage then     
        addEventHandler('onClientRender',root,move_image) 
        renderImage = true 
    end 
end 

You can delete images every single moment you want and the render function will stop when there isn't anything to render.

imageTable[element]= nil 

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...