Jump to content

Is there possible to make a delay inside loop ??


bandi94

Recommended Posts

So i am making a list , data's are stored in a table .

Now i use "for.... in pairs() do " and GuiLabel's (not the MTA one's , custom one from my own dxGui) , and i wanna to make a delay of 100ms between row's.

Ex. draw the first line , wait 100ms , draw secound line , wait 100ms , .........

Now i made a simpel loop delay using , "while do" and "getTickCount" , but there is a problem , i have 30 line's so there is 30*100ms = 3s , when i press the button the game freez for 3s and after show's all the 30 line's.

Is there any way to delay the "in pairs" with table ??

Link to comment
  
local your_table = {}; -- this will be your table in which yor data is stored. 
local label_to_render; -- this will hold the label to be rendered.  
  
-- I suppose you have a function, like draw_label, that draws a label... 
-- for example... 
function draw_label (theLabel) ... end;  
  
  
addEventHandler ("onClientRender", getRootElement(), 
      function ()  
           -- draw the selected label. 
           draw_label (label_to_render);  
      end);  
  
local next_index = next(your_table);  
label_to_render = your_table [next_index];  
setTimer (             -- this timer will change the selected label every 100ms 
      function () 
              next_index = next(your_table,next_index);  
              label_to_render = your_table[next_index];  
      end, 100, 1);  
  

Link to comment

@IIYAMA, Vector: I think he should change his gui system to make it possible.

There is a way to actually make a delay inside a loop. Here is my simple example:

local a = { 1, 2, 3, 4 } 
  
local c = coroutine.create (  
    function () 
        for i, v in ipairs ( a ) do 
            outputChatBox ( v ) 
            coroutine.yield () 
        end 
    end ) 
     
setTimer (  
    function () 
        coroutine.resume ( c ) 
    end , 100, 4 ) 

Link to comment

@ Vector , i wanna to draw them with a 100ms delay , but not one by one (at the end i wanna see all the 30 line's). And my custom label has his own drawing function so i only call a creating function with export after that he is drawed by his own function. (Like export........CreateDxLabel(bla,bla) after that he is auto drawed until it's destroyed or set to false the visible value.)

@csiguusz , thx very much your way it's just working great with my custom label's :D

Off topic (En is tudok maggyarul :D)

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