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: Allowing a function to run multiple times at once.

Previous Thread :: Next Thread 
joshuarome is not online. joshuarome
Joined: 29 Aug 2008
Total Posts: 135
14 Sep 2015 01:31 PM
I have been recently trying to re-create an time-efficient function which can run multiple times at once with different parameters, whilst still being time efficient. So far, I have tried both coroutines and spawn(function() code blabla end), but both of these methods add several seconds onto my program and I do not want to use these methods.

Any ideas/suggestions upon how I can allow my function to run multiple times at once will be greatly appreciated, regards.
Report Abuse
louiskk is not online. louiskk
Joined: 31 Dec 2008
Total Posts: 228
14 Sep 2015 01:34 PM
Can you post your code, that's not really much to go on. We don't know the context.
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
14 Sep 2015 01:35 PM
You are doing it wrong.


Muad'Dib
Report Abuse
fishguy100 is not online. fishguy100
Joined: 16 Feb 2013
Total Posts: 3679
14 Sep 2015 01:36 PM
Did you try delay?

Did you try putting spawn IN the function?
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
14 Sep 2015 01:36 PM
Lua by nature is not an efficient language. If doing that is adding seconds on to your execution time, perhaps you are doing too much for it to handle. I have no better ideas though.
Report Abuse
lordrambo is not online. lordrambo
Joined: 16 Jun 2009
Total Posts: 20628
14 Sep 2015 01:39 PM
"Any ideas/suggestions upon how I can allow my function to run multiple times at once will be greatly appreciated, regards."

without spawn/delay (a new thread - another core involved) it's impossible
neither coroutines nor spawn should slow down your script's execution by any realistic amount

anyway post function because spawn should work just fine
Report Abuse
joshuarome is not online. joshuarome
Joined: 29 Aug 2008
Total Posts: 135
14 Sep 2015 01:42 PM
local p = game.Workspace.Part
local b = game.Workspace.Part3
local cf = CFrame.new
local s = game:GetService("RunService").RenderStepped

local function interpolate(object,target,frames)
local t = tick()
local c = coroutine.create(function()
local delta;
local cx,cy,cz,c00,c01,c02,c10,c11,c12,c20,c21,c22 = object.CFrame:components()
local tx,ty,tz,t00,t01,t02,t10,t11,t12,t20,t21,t22 = target:components()
for i = 0, frames do
delta = i/frames
local cx,cy,cz,c00,c01,c10,c10,c11,c12,c20,c21,c22 =
cx+(tx-cx)*delta,cy+(ty-cy)*delta,cz+(tz-cz)*delta,
c00+(t00-c00)*delta,c01+(t01-c01)*delta,c02+(t02-c02)*delta,
c10+(t10-c10)*delta,c11+(t11-c11)*delta,c12+(t12-c12)*delta,
c20+(t20-c20)*delta,c21+(t21-c21)*delta,c22+(t22-c22)*delta

s:wait()
object.CFrame = cf(cx,cy,cz,c00,c01,c10,c10,c11,c12,c20,c21,c22)
end
end)
coroutine.resume(c)
print(tick()-t)
end

interpolate(p,cf(60,60,60),60)
interpolate(p3,cf(-60,-60,-60),60)

That is the code, without coroutines, the function will only execute one by one, but the code will execute and run in around 1.8-9 seconds. However with coroutines, the function will execute both interpolations at the same time, however alot slower with an average at 2.6702880859375e-005 seconds.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
14 Sep 2015 01:48 PM
Not to criticize your code (Especially when you seem to know what you're doing) but I recommend Roblox's new lerp method of CFrame, as it's probably a lot more efficient.
Report Abuse
fishguy100 is not online. fishguy100
Joined: 16 Feb 2013
Total Posts: 3679
14 Sep 2015 01:52 PM
This code is the EXACT code used in the framework of phantom forces. Nice try m8.
Report Abuse
larr1212 is not online. larr1212
Joined: 06 Jan 2015
Total Posts: 259
14 Sep 2015 02:03 PM
Roblox CFrame lerp method[2]


Muad'Dib
Report Abuse
joshuarome is not online. joshuarome
Joined: 29 Aug 2008
Total Posts: 135
14 Sep 2015 02:04 PM
Yeah, its not. They use quaternions rotation, this uses matrix rotations. Don't try to spread rumors that you don't know about, I'm friends with both Lito and Axis.
Report Abuse
joshuarome is not online. joshuarome
Joined: 29 Aug 2008
Total Posts: 135
14 Sep 2015 02:05 PM
Yeah, I've heard of it, just wanted to create my own as a personal challenge
Report Abuse
SenseiWarrior is online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
14 Sep 2015 02:12 PM
function yo()
wait(1)
print'1'
end
for i=1,3 do
coroutine.resume(coroutine.create(function()yo()end))
end

#code return
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