Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Lua ➜ how to run codes in order?

how to run codes in order?

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Supertu   (4 posts)  Bio
Date Mon 09 Mar 2015 05:43 PM (UTC)

Amended on Mon 09 Mar 2015 06:59 PM (UTC) by Supertu

Message
function check_status()

local l= wait.regexp("You are dead", 5)
if l==nil then
print('Timeout')
return 1
else
print('Triggered')
return 0
end --if
end --function


co=coroutine.create(check_status)

local x,y=coroutine.resume(co)

if y==1 then
print('You are still alive')
end

if y==0 then
print('You are absolutly dead')
end

if y==nil then
print('Nothing returned')
end

-------------------Code-----------------------------

It always printed 'Nothing returned' and seems to skip over the process of 'check_status' called by coroutine


How can I get the return value firstly and then go do something else?

Best regards.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Mon 09 Mar 2015 09:46 PM (UTC)
Message
First check the return status:


 local y = assert (coroutine.resume(co))


Second, indent your code! It looks terrible. How can you work out what is inside an "if" and what isn't?

Third, is this running inside a "wait.lua" coroutine? So you have a coroutine inside a coroutine? What are you doing exactly?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #2 on Mon 09 Mar 2015 09:47 PM (UTC)
Message
If the code is indented use code tags so we can see it:

Template:codetag To make your code more readable please use [code] tags as described here.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Supertu   (4 posts)  Bio
Date Reply #3 on Tue 10 Mar 2015 03:00 PM (UTC)

Amended on Thu 12 Mar 2015 05:52 AM (UTC) by Supertu

Message
I have already known how to do it due to Nick's kindly help.

Thanks a lot!
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


15,996 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.