Jump to content

Can I 'pause' a for loop?


'LinKin

Recommended Posts

Posted

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?

Need a clanwar script? Click here!

Do you want some free scripts for your DD server? Visit my website.

Posted

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 

I used to know how to code, but then I took an arrow in the knee.

Project Redivivus - Remaking Old School MTA With New Code

MTA 0.6 Nightly 1 released

Posted

No, that function is working on current release ( 1.3.5 ).

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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