123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|396|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Blitz -> Update All Objects in Array?

Fri, 23 Jun 2017, 18:56
Caton
I tried it, but can't get it to work a little help please?
thanks.

Fri, 23 Jun 2017, 19:45
Pakz
I see a "end select" there that is probably causing a problem.
Fri, 23 Jun 2017, 20:09
Caton


I forgot to remove it, anyways It will only update one object, but not all of them,how do I get it to update all objects?
Sat, 24 Jun 2017, 03:34
Jayenkai


-=-=-
''Load, Next List!''
Tue, 27 Jun 2017, 05:26
Afr0
Note: I'm not going to provide any code here, but make a general comment. When updating all objects in an array (or a linked list, or a dictionary, or whatever), you generally want to check which objects *need* to be updated before updating.
*Unless* you're sure that your collection is never going to grow large enough that speed is going to be an issue. But, you know, it's always better to be on the safe side.

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Tue, 27 Jun 2017, 06:00
Jayenkai
Indeed, although as with most code-speed dilemmas, it depends a lot on the language and OS. Best to stress test (hundreds and thousands per second, time it) to find the best solution.

In most cases "check if it needs updating" + "update if it does" vs "just update EVERYTHING", there won't actually be "too" much of a difference, unless there's a lot to update.
Remember that "check+update" is actually two things, so anything that does need updating will require two commands/lookups/etc.

The speed will depend on how well the data is stored, whether it's quicker to read than write, and a number of other factors.

In the majority of cases, if you know you're going to update "most" of the elements, then it's better to brute-force it.
Only when it's less than about half would it be worth checking into the speed of such things, to find whether it makes any difference.

This is one reasons I've always preferred arrays to lists.
To me, having to scan a whole list to reach element 100 is rather wasteful when, if it were an array, I could simply jump straight to #100.. if, on the other hand, I was coding something that NEEDED to scan all the objects, then a long list would probably be quicker than lots of array references.

You need to test these things, and find out what's best for the circumstances.

-=-=-
''Load, Next List!''