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 » Scripters
Home Search
 

Re: Coroutine.yield not yielding

Previous Thread :: Next Thread 
secret6timb1 is not online. secret6timb1
Joined: 11 Sep 2013
Total Posts: 1817
11 Jul 2015 12:04 PM
So, Heres a coroutine I made

local swing = coroutine.wrap(function(n)
local nothing = 0
while true do
connect["Right Arm->Torso"].C1 = connect["Right Arm->Swing"]
wait(.5)
connect["Right Arm->Torso"].C1 = connect["Right Arm->Torso->Internal"]
print("Done")
nothing = coroutine.yield()
end
end)

(connect[]'s are just for my welding stuff)

It keeps printing "Done" every .5 seconds
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
11 Jul 2015 12:12 PM
You need "break", not coroutine.yield.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
11 Jul 2015 12:18 PM
No, I'm pretty sure he wants to yield it so he can call swing later.
Report Abuse
secret6timb1 is not online. secret6timb1
Joined: 11 Sep 2013
Total Posts: 1817
11 Jul 2015 12:31 PM
Yeah I wanted to use this as a function, but a function that could be ran while my main code still runs...

Does coroutine.yield() not work for roblox?
Report Abuse
secret6timb1 is not online. secret6timb1
Joined: 11 Sep 2013
Total Posts: 1817
11 Jul 2015 12:37 PM
I compiled lua in visual studio and coroutine.yield works just fine there.

How do I implement this for roblox?

I want it to wait (be suspended) until the function (coroutine.wrap) is called again
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
11 Jul 2015 12:42 PM
Again, since you want to yield every loop, either remove the loop, or put a break statement.
Report Abuse
secret6timb1 is not online. secret6timb1
Joined: 11 Sep 2013
Total Posts: 1817
11 Jul 2015 12:43 PM
You cant, Once a coroutine.wrap ends you cant call swing() again because the coroutine is "dead" and there is no way to restart it.

In wiki it uses coroutine.yield.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
11 Jul 2015 12:45 PM
Well then just use spawn() instead of making a coroutine.
Report Abuse
secret6timb1 is not online. secret6timb1
Joined: 11 Sep 2013
Total Posts: 1817
11 Jul 2015 12:50 PM
I dont think theres a coroutine.spawn
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
11 Jul 2015 01:01 PM
It's a Roblox-specific function.


spawn(swing) -- "swing" should be a function, not a coroutine. Be warned that you can't send arguments through "spawn".
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
11 Jul 2015 01:02 PM
OP I think it might have something to do with having a wait function call in there, I tested this and it worked fine on Roblox:

local test = coroutine.wrap(function()
while true do
print(coroutine.yield());
end
end);

test();
test("Hi");
test("Bye");
Report Abuse
secret6timb1 is not online. secret6timb1
Joined: 11 Sep 2013
Total Posts: 1817
11 Jul 2015 01:15 PM
I changed it to a coroutine.create and coroutine.yield still doesnt work.

I really need the wait in there though

Is there a way I can delay in a coroutine without wait?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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