how to run codes in order?

Posted by Supertu on Mon 09 Mar 2015 05:43 PM — 4 posts, 16,859 views.

#0
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.
Amended on Mon 09 Mar 2015 06:59 PM by Supertu
Australia Forum Administrator #1
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?
Australia Forum Administrator #2
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.
#3
I have already known how to do it due to Nick's kindly help.

Thanks a lot!