|
| 27 Jan 2013 05:05 PM |
function something() wait(10) print("1") end
something() print("2")
How can I make it so 2 prints before 1? |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2013 05:07 PM |
Well, in your case you can do two things.
1) Move the second print above 'something()' 2) Use a coroutine (The first suggestion makes more sense to do in this instance.)
|
|
|
| Report Abuse |
|
|
crouton04
|
  |
| Joined: 07 Jul 2010 |
| Total Posts: 4459 |
|
|
| 27 Jan 2013 05:10 PM |
function something(arg) return print(tostring(arg)) end
something(10) |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2013 05:11 PM |
How would I use a coroutine for this? I checked the wiki but it doesn't help |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2013 05:13 PM |
| For this example you wouldn't want to use a coroutine since there is no need since you can just reorder it. |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2013 05:14 PM |
| I need to use a coroutine -.- |
|
|
| Report Abuse |
|
|
Saltless
|
  |
| Joined: 24 Dec 2012 |
| Total Posts: 107 |
|
|
| 27 Jan 2013 05:14 PM |
It's more logical to bump the 'print("2")' up, but if you insist.
coroutine.resume(coroutine.create(function() wait(10) print("1") end))
print("2")
--A fry without salt? Bring it back to McDonalds. Well, get to moving! |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2013 05:16 PM |
Thanks The code I used was just an example |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2013 05:17 PM |
Why isn't this working?
coroutine.resume(coroutine.create(_G.something("1"))) |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2013 05:21 PM |
Hmm I usually use coroutine.wrap...
function bob() print "hi" end local fun = coroutine.wrap(bob) fun()
|
|
|
| Report Abuse |
|
|
|
| 27 Jan 2013 05:22 PM |
| bad argument #1 to 'wrap' (Lua function expected) |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2013 05:25 PM |
| works fine...I just tested it... |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2013 05:26 PM |
function bob() wait(3) print "2" end local fun = coroutine.wrap(bob) print"1" fun()
>>1 >>2 |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2013 05:36 PM |
coroutine.resume(coroutine.create(_G.something("1"))) ^ Error
coroutine.wrap(_G.something("1")) ^ Error |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2013 05:37 PM |
with coroutine.wrap do:
local something = coroutine.wrap(_G.something) something("1") |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2013 05:39 PM |
with coroutine.resume do:
coroutine.resume(coroutine.create(_G.Something),"1") |
|
|
| Report Abuse |
|
|
| |
|