While object for MMF/Flash?
I've been trying to use fastloops with Flash, but they behave odd compared to an exe. They tend to slow down things the more fastloops and conditions you use. Are there any plans to fix this?
Also, I use fastloops to simulate a while block but it kinda feels unnatural. So, again, any plans to create a "While" object for flash?
Re: While object for MMF/Flash?
Flash IS slower than C++, you can use fastloop but you must restrict the number of loops to a minimum.
Re: While object for MMF/Flash?
Use the Flash version of the for each object instead spread value/loop. It's considerably faster.
Re: While object for MMF/Flash?
The ForEach object (even with the patch) still has a bug in the Flash version where objects are deleted it can crash your flash file. I've sent the details to Francois so hopefully it will get fixed. But why would the ForEach object be faster than a fastloop? It's doing the same thing, it's just quicker to set up in MMF?
Re: While object for MMF/Flash?
AndyH, didn't Jamie write an unofficial bug fix for that error?
Re: While object for MMF/Flash?
For each is not that much faster than fastloop actually. It looks to me that it is pretty much the same.
Re: While object for MMF/Flash?
It depends how many loops you're doing. If you do the classic spread value/loop thing, it actually has to loop through all of the objects up to the loop index every loop to compare the alterable value.
Here's an example of what MMF has to do when looping through 5 actives. What happens internally is coloured in red.
Without the For Each object
[size:8pt]Spread value 0 in Alterable Value A of Active
(Active 1) : Set Alterable Value A to 0
(Active 2) : Set Alterable Value A to 1
(Active 3) : Set Alterable Value A to 2
(Active 4) : Set Alterable Value A to 3
(Active 5) : Set Alterable Value A to 4
Start loop "foo" NObjects("Active") times
(first loop) On loop "foo"
+ Alterable Value A("Active") = LoopIndex("foo")
(Active 1) : Is Alterable Value A equal to 0?
(Yes - object is now selected)
(Active 2) : Is Alterable Value A equal to 0?
(No)
(Active 3) : Is Alterable Value A equal to 0?
(No)
(Active 4) : Is Alterable Value A equal to 0?
(No)
(Active 5) : Is Alterable Value A equal to 0?
(No)
(Actions run here)
(second loop) On loop "foo"
+ Alterable Value A("Active") = LoopIndex("foo")
(Active 1) : Is Alterable Value A equal to 1?
(No)
(Active 2) : Is Alterable Value A equal to 1?
(Yes - object is now selected)
(Active 3) : Is Alterable Value A equal to 1?
(No)
(Active 4) : Is Alterable Value A equal to 1?
(No)
(Active 5) : Is Alterable Value A equal to 1?
(No)
(Actions run here)
(third loop) On loop "foo"
+ Alterable Value A("Active") = LoopIndex("foo")
(Active 1) : Is Alterable Value A equal to 2?
(No)
(Active 2) : Is Alterable Value A equal to 2?
(No)
(Active 3) : Is Alterable Value A equal to 2?
(Yes - object is now selected)
(Active 4) : Is Alterable Value A equal to 2?
(No)
(Active 5) : Is Alterable Value A equal to 2?
(No)
(Actions run here)
(fourth loop) On loop "foo"
+ Alterable Value A("Active") = LoopIndex("foo")
(Active 1) : Is Alterable Value A equal to 3?
(No)
(Active 2) : Is Alterable Value A equal to 3?
(No)
(Active 3) : Is Alterable Value A equal to 3?
(No)
(Active 4) : Is Alterable Value A equal to 3?
(Yes - object is now selected)
(Active 5) : Is Alterable Value A equal to 3?
(No)
(Actions run here)
(fifth loop) On loop "foo"
+ Alterable Value A("Active") = LoopIndex("foo")
(Active 1) : Is Alterable Value A equal to 4?
(No)
(Active 2) : Is Alterable Value A equal to 4?
(No)
(Active 3) : Is Alterable Value A equal to 4?
(No)
(Active 4) : Is Alterable Value A equal to 4?
(No)
(Active 5) : Is Alterable Value A equal to 4?
(Yes - object is now selected)
(Actions run here)
[/size]
With the For Each object
[size:8pt]Start For Each loop "foo" for "Active"
(Loops through all the actives ONCE, selecting each and triggering the "On For Each Loop" condition)
On For Each loop "foo" for "Active"
(Actions run here)[/size]
As you can see, the difference is huge. With 5 actives MMF has to compare the alterable value of an active 25 times to loop through them once, vs 0 times with the For Each object. You wouldn't notice that, but imagine when you have 500 actives? That would be 250000 comparisons, vs 0 with the For Each object.
Comparing an alterable value is nothing like comparing a value in C or pure ActionScript - it has all the overhead of calling a condition, the object selection routines, the MMF types - because the C runtime is C, this overhead is compensated for because processors are fast. In ActionScript, the overhead really matters, because you basically have the processor running Flash Player interpreting ActionScript bytecode interpreting MMF bytecode.
I did a small board game a while ago which had to loop through about 300 objects, and this took 2 seconds without the For Each object (in Flash) and was instant with the For Each object.
Re: While object for MMF/Flash?
Interesting to know Jamie. DizzyDoo I have that fix (the updated DAT file) but the problem, or similar problem, still exists.
I've only sent the file to Francois last week, where everything was working in my SWF file until I made a change, then when running the SWF only three things were working, other instances and all other events were not working. Francois identified something in the ForEach object was crashing and mentioned something about destroying objects and memory. I tried downloading that fix again, just to be sure (I was sure I had already installed it) but there was no change. Replacing the ForEach object for Fastloops and my SWF worked again. Hopefully the problem can be located and fixed soon, especially as there is an advantage of using this object.
Re: While object for MMF/Flash?
For info, this is what Francois found: "It crashes right in the middle of the selectOneObjectForCondition routine.". This post is where I got the latest DAT file:
http://www.clickteam.com/epicenter/ubbthreads.php?ubb=showflat&Number=186462#Post1864 62
Re: While object for MMF/Flash?
Good to know all this info.
The thing is that I need a "while" sentence where I can fast loop through a set of sentences or repeat them as long a condition is met, and even though I can mimic that with FastLoop and ForEach is cumbersome. Any plans for a "While" object (I mean, with a similar fast execution)?
Re: While object for MMF/Flash?
Quote:
Originally Posted by Jamie
It depends how many loops you're doing. If you do the classic spread value/loop thing, it actually has to loop through all of the objects up to the loop index every loop to compare the alterable value.
Wouldn't it actually have to loop all the objects, not just "up to the loop index"? MMF doesn't know that only one object matches the loop index, so it tests them all.
I realise I'm telling someone at Clickteam how their own software works, I'll look a fool if I'm wrong...
Re: While object for MMF/Flash?
No you won't. I thought that was strange, too.
Re: While object for MMF/Flash?
Quote:
Originally Posted by Dynasoft
Quote:
Originally Posted by Jamie
It depends how many loops you're doing. If you do the classic spread value/loop thing, it actually has to loop through all of the objects up to the loop index every loop to compare the alterable value.
Wouldn't it actually have to loop all the objects, not just "up to the loop index"? MMF doesn't know that only one object matches the loop index, so it tests them all.
I realise I'm telling someone at Clickteam how their own software works, I'll look a fool if I'm wrong...
Ah, I guess you must be right. I'm the fool here :)
That makes the spread/loop thing even slower, then.
EDIT: I corrected my post
Re: While object for MMF/Flash?
The original behavior might be correct if you can move to the next loop when you find one object that meets the condition.
Re: While object for MMF/Flash?
That's what I thought originally, but it does need to check all the objects since it doesn't know if there's more than one with the same alterable value, in which case they'd both get selected.