|
| 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
|
  |
| 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
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 14 Sep 2015 01:35 PM |
You are doing it wrong.
Muad'Dib |
|
|
| Report Abuse |
|
|
| 14 Sep 2015 01:36 PM |
Did you try delay?
Did you try putting spawn IN the function? |
|
|
| Report Abuse |
|
|
| 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
|
  |
| 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 |
|
|
| 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 |
|
|
| 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 |
|
|
| 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
|
  |
| Joined: 06 Jan 2015 |
| Total Posts: 259 |
|
|
| 14 Sep 2015 02:03 PM |
Roblox CFrame lerp method[2]
Muad'Dib |
|
|
| Report Abuse |
|
|
| 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 |
|
|
| 14 Sep 2015 02:05 PM |
| Yeah, I've heard of it, just wanted to create my own as a personal challenge |
|
|
| Report Abuse |
|
|
| 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 |
|