Davidii
|
  |
| Joined: 17 Jul 2008 |
| Total Posts: 1282 |
|
|
| 08 Nov 2011 06:23 PM |
We all know the classic
while true do end
crash ROBLOX thingy. I think we can all agree that this was a design flaw - forcing us to constantly use a wait() statement, keeping our scripts only running once every two processes.
Is it possible to overcome this? To create a script that runs every frame, instead of every other?
Here's something I think might work.
function runEveryFrame() print("This should run every frame.") end
function loop() while true do runEveryFrame() wait() --keeps us down to every other process end end
delay(0, loop()) loop()
The second loop call will begin immediately, whereas the first loop call will start while the second is "pausing," therefore running everything in runEveryFrame once per frame. Would this work? |
|
|
| Report Abuse |
|
|
|
| 08 Nov 2011 06:27 PM |
I think the only use of this would be in camera manipulation.
But yes, I believe that would work. |
|
|
| Report Abuse |
|
|
Davidii
|
  |
| Joined: 17 Jul 2008 |
| Total Posts: 1282 |
|
|
| 08 Nov 2011 06:27 PM |
| Well, if you wanted to make a REALLY fast gun. Or something... |
|
|
| Report Abuse |
|
|
|
| 08 Nov 2011 06:32 PM |
>delay(0, loop())
--> starting loop before calling delay
nope.avi
delay(0, loop) |
|
|
| Report Abuse |
|
|
|
| 08 Nov 2011 06:34 PM |
| But... if you run that, wouldn't it make EVERY other thread unable to run? |
|
|
| Report Abuse |
|
|
Davidii
|
  |
| Joined: 17 Jul 2008 |
| Total Posts: 1282 |
|
|
| 08 Nov 2011 06:35 PM |
| Whoopsie. Well, correct that error and it would still work. |
|
|
| Report Abuse |
|
|
|
| 08 Nov 2011 06:36 PM |
You say it's a design flaw to prevent users from taking all the CPU, leaving no CPU for other threads?
If I was the one that designed it, it'd be intended... |
|
|
| Report Abuse |
|
|
Davidii
|
  |
| Joined: 17 Jul 2008 |
| Total Posts: 1282 |
|
|
| 08 Nov 2011 06:37 PM |
| This creates two identical threads, running every other process, so that the same function is run every process. |
|
|
| Report Abuse |
|
|
XlegoX
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 14955 |
|
|
| 08 Nov 2011 06:51 PM |
Bad idea. As soon as the game lags even slightly you'll have have no guarantees anymore. Remember, wait() waits AT LEAST the time you pass it, but possibly much much longer if the game has a lag-spike. With sufficient synchronization you should be able to keep them running out of phase, but it won't be anywhere near that trivial.
That's ASSUMING THAT WAIT WAITS MINIMUM TWO FRAMES of course, which I don't believe is the case!
As far as I know wait() will correctly run the script once every single frame. When you see artifacts trying to do stuff with the camera it's because the game-step happens BETWEEN the script execution step and the render step. That means that even if you have your script do it's thing every frame, it will always be at least one physics step behind the render. |
|
|
| Report Abuse |
|
|
|
| 08 Nov 2011 07:05 PM |
| game:GetService("RunService").Heartbeat:connect(function() print("Frame?") end) |
|
|
| Report Abuse |
|
|
|
| 09 Nov 2011 08:34 AM |
@XLegoX
I think its because the rendering is 60 fps and the physics and scripts are 30? |
|
|
| Report Abuse |
|
|
HotThoth
|
  |
 |
| Joined: 24 Aug 2010 |
| Total Posts: 1176 |
|
|
| 09 Nov 2011 12:59 PM |
This sounds like an experiment in crashing ROBLOX. RUN AWAYYYY!
This type of system does not seem very helpful, but there are cases where you're doing a lot of computation in-script, and it can be useful to delegate when you want your script to yield (to find the balance between freezing ROBLOX and having your script take longer than necessary). For an example of this, check out some of the terrain plug-ins-- operations over the entire Terrain object require a careful allotment of wait() statements: too few and ROBLOX would appear to crash until the calculations are done (annoying), too many and the calculations would take tons more time than necessary. One way to balance this is to see how many operations you're doing, and just put a wait() statement every 100,000 operations or so, depending on how costly those operations are. [This assumes that the "doOperation" function call takes a lot more time than the line beneath it].
local waitCount = 0 for i = 1, giantLoopOfCalculation do doOperation() if waitCount > 100,000 then waitCount = 0 wait() else waitCount = waitCount + 1 end end |
|
|
| Report Abuse |
|
|
|
| 09 Nov 2011 01:12 PM |
@hotthot
eww thats ugly
local count=0 for i=1,giantloopofcalc do doOp() count=(count+1)%100000 if count==0 then wait() end end |
|
|
| Report Abuse |
|
|
|
| 09 Nov 2011 01:36 PM |
waitCount = waitCount > 100000 and 0 or waitCount + 1
Instead of the if statement couldn't you use that? |
|
|
| Report Abuse |
|
|
Davidii
|
  |
| Joined: 17 Jul 2008 |
| Total Posts: 1282 |
|
|
| 09 Nov 2011 06:05 PM |
I got a mod post. Hooah.
Well, EGO, if we can't really fix up the Camera at all... well then... Bwaaargh. Hopefully the mods are working on something to fix up the Camera, make it more usable. |
|
|
| Report Abuse |
|
|
|
| 09 Nov 2011 06:15 PM |
| we have some ideas as to how to make it easier for you guys to manipulate the camera. Also, I love hearing the problems/suggestions you guys have with the current camera. |
|
|
| Report Abuse |
|
|
Slizerd
|
  |
| Joined: 15 Jun 2011 |
| Total Posts: 113 |
|
|
| 09 Nov 2011 06:16 PM |
@jedi;
Make cutscenes easier; give us some method for making the camera glide smoothly to a certain CFrame. |
|
|
| Report Abuse |
|
|
|
| 09 Nov 2011 06:19 PM |
@jedi
problem: no camerascope. |
|
|
| Report Abuse |
|
|
Davidii
|
  |
| Joined: 17 Jul 2008 |
| Total Posts: 1282 |
|
|
| 09 Nov 2011 06:20 PM |
| Kind of like the Tween functions for GUIs. You know - if I knew that suggestions actually got noticed here, I'd put them here instead of the Ideas and Suggestions forum... |
|
|
| Report Abuse |
|
|
|
| 09 Nov 2011 06:59 PM |
| The other one does, I just read this forum a lot. |
|
|
| Report Abuse |
|
|
|
| 09 Nov 2011 07:00 PM |
@David
>assuming that the suggestions their are not drained out by hat requests. |
|
|
| Report Abuse |
|
|