Jump to content

Can I 'pause' a for loop?


'LinKin

Recommended Posts

Hello,

I want to insert some values to a table, one of these values must be typed by the client first.

Here's the idea:

  
for i = 1, 5, 1 do 
    table.insert(someTable, {idx = i, text = myFunction()}) 
end 
  
function myFunction() 
     --I'd create an editBox in a window here, and a button "OK" 
     addEventHandler("onClientGUIClick", aButton, doClick, false) 
end 
  
function doClick() 
     return guiGetText(anEditBox) 
end 
  

That's wrong, but that's the idea of what I want to do.

How can I make the for loop not move to the next iteration but only untill the player clicks the OK button in a window?

Link to comment

No, no, no. Coroutines make no sense for this purpose. What you need to do is count the times the player has clicked the button "OK" - every time it is pressed, you grab the text from the edit box and you add it to the table. Once it reaches 5, you stop it - you handle it however you want.

So, something like this:

local someTable = {} 
local GUI = {} 
local clickedTimes = 0 
  
function createGUI () 
  
    -- Create the GUI however you want 
    GUI.editBox = guiCreateEdit ( ... ) 
    GUI.buttonOk = guiCreateButton ( ... ) 
  
    addEventHandler ( "onClientGUIClick", GUI.buttonOk, onOkClick, false ) 
  
end 
  
function onOkClick () 
  
    if clickedTimes < 5 then 
        -- You can handle user input here, for instance, check if the player has actually  
        -- written anything on the edit box at all by checking if the length of the string returned from guiGetText is higher than 0 
        table.insert ( someTable, guiGetText ( GUI.editBox ) ) 
  
        clickedTimes = clickedTimes + 1 
    end 
  
end 

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