Jump to content

[Question] How can i continue the loop after getting thing from value?


iMr.WiFi..!

Recommended Posts

Posted (edited)

Hello guys!
as i write in title, I have small question it's about loop!
i've small loop, ok?
i want stop loop in every value and calls a functions and wait a response from function, if function give any value i want to continue the loop!
anyone have idea or suggest to help me at this?

Edited by iMr.WiFi..!

Experienced MTA developer for 4 years. | MTA خبرة 4 سنين في برمجة

ليس عليك اسعاد الجميع ,
ولكن عليك بإن لا تؤذي أحداً 

=========
You do not have to make everyone happy,
But you should not hurt anyone

 

Want to contact with me?

 

Discord: JustCarry#2616 (Always there)
Skype: Live:JustCarry10 (Not always)

  • Moderators
Posted

If not A-sync, then:

function testFunction ()
	return math.random(1000) % 2 == 0
end

function start ()
  for i=1, 1000 do
      local value = testFunction()
      if value then
          print(value)
      else
          break
      end
  end
end

start()

 

If A-sync, use:

https://www.lua.org/pil/9.1.html

 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
2 hours ago, Overkillz said:

Inside the loop

if value == "whatever" then

-- whatever u want to do

return

end

There timer on function before give a value.

1 hour ago, IIYAMA said:

If not A-sync, then:


function testFunction ()
	return math.random(1000) % 2 == 0
end

function start ()
  for i=1, 1000 do
      local value = testFunction()
      if value then
          print(value)
      else
          break
      end
  end
end

start()

 

If A-sync, use:

https://www.lua.org/pil/9.1.html

 

Will coroutine working in mta? because 'os' and 'io' libraries weren't worked with me!


 

Experienced MTA developer for 4 years. | MTA خبرة 4 سنين في برمجة

ليس عليك اسعاد الجميع ,
ولكن عليك بإن لا تؤذي أحداً 

=========
You do not have to make everyone happy,
But you should not hurt anyone

 

Want to contact with me?

 

Discord: JustCarry#2616 (Always there)
Skype: Live:JustCarry10 (Not always)

  • Moderators
Posted (edited)

Coroutine does work.

 

Edited by IIYAMA
  • Thanks 1

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
1 hour ago, IIYAMA said:

Coroutine does work.

 

Thanks! that works.

  • Like 1

Experienced MTA developer for 4 years. | MTA خبرة 4 سنين في برمجة

ليس عليك اسعاد الجميع ,
ولكن عليك بإن لا تؤذي أحداً 

=========
You do not have to make everyone happy,
But you should not hurt anyone

 

Want to contact with me?

 

Discord: JustCarry#2616 (Always there)
Skype: Live:JustCarry10 (Not always)

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