Indexing array problem
BlitzPlus Forums/BlitzPlus Programming/Indexing array problem
| ||
I needed a fast way to look up a type object by an identifier without having to look at every single one to compare it, so I made this:;IndexStars. Updates the star index. Call this right after you've altered the galaxy in some way. Function IndexStars() numstars=0 For galaxy.star=Each star ;Count the stars. numstars=numstars+1 Next DebugLog("Starcount="+numstars) Dim starindex(numstars) ;Make starindex big enough to hold each and every star. For galaxy.star=Each star starindex(galaxy\StarID)=galaxy.star Next End Function StarID is a field set at star creation, it's the number of the star (first star created has starID of 0, second has starID of 1, etc). It compiles without error, but if I try to access this index like so: galaxy.star=starindex.star(StarID) starx=galaxy\x stary=galaxy\y I get a Runtime Error saying "Object does not exist". What did I do wrong? Last edited 2010 |