generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Continue script without waiting for function to finish

Previous Thread :: Next Thread 
batistapowerbonbtla is not online. batistapowerbonbtla
Joined: 16 Dec 2011
Total Posts: 2203
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
leolion113 is not online. leolion113
Joined: 11 Oct 2008
Total Posts: 3336
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 is not online. 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
batistapowerbonbtla is not online. batistapowerbonbtla
Joined: 16 Dec 2011
Total Posts: 2203
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
leolion113 is not online. leolion113
Joined: 11 Oct 2008
Total Posts: 3336
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
batistapowerbonbtla is not online. batistapowerbonbtla
Joined: 16 Dec 2011
Total Posts: 2203
27 Jan 2013 05:14 PM
I need to use a coroutine -.-
Report Abuse
Saltless is not online. 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
batistapowerbonbtla is not online. batistapowerbonbtla
Joined: 16 Dec 2011
Total Posts: 2203
27 Jan 2013 05:16 PM
Thanks
The code I used was just an example
Report Abuse
batistapowerbonbtla is not online. batistapowerbonbtla
Joined: 16 Dec 2011
Total Posts: 2203
27 Jan 2013 05:17 PM
Why isn't this working?

coroutine.resume(coroutine.create(_G.something("1")))
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
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
batistapowerbonbtla is not online. batistapowerbonbtla
Joined: 16 Dec 2011
Total Posts: 2203
27 Jan 2013 05:22 PM
bad argument #1 to 'wrap' (Lua function expected)
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
27 Jan 2013 05:25 PM
works fine...I just tested it...
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
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
batistapowerbonbtla is not online. batistapowerbonbtla
Joined: 16 Dec 2011
Total Posts: 2203
27 Jan 2013 05:36 PM
coroutine.resume(coroutine.create(_G.something("1")))
^ Error

coroutine.wrap(_G.something("1"))
^ Error
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
27 Jan 2013 05:37 PM
with coroutine.wrap do:

local something = coroutine.wrap(_G.something)
something("1")
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
27 Jan 2013 05:39 PM
with coroutine.resume do:

coroutine.resume(coroutine.create(_G.Something),"1")
Report Abuse
batistapowerbonbtla is not online. batistapowerbonbtla
Joined: 16 Dec 2011
Total Posts: 2203
27 Jan 2013 05:42 PM
It worked, thanks!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image