Thread: Hero.Epic
View Single Post
Nightfox
Senior Member
 
Join Date: Dec 2011
Posts: 100

Old November 29th, 2016, 01:04 PM
Quote:
Originally Posted by ShadowChemosh View Post
My confusion in going over this is the way you structured the foreach loops:
The simple answer is that I have tried very hard to avoid foreach loops and so have little experience with them. Most of what I have done in the past with them has been copy/paste with slight slight changes to fit a need. This is why I am welcoming input in the hopes of finding a way to simplify or even get rid of some of those nasty things.

Quote:
Originally Posted by ShadowChemosh View Post
Code:
foreach pick on hero where (field[cIndex].value < 20)
If you are going to do a foreach loop then at least limit the context down by component sets. This loop here goes after every PICK on the hero then tries to subset by a field that may or may not even exist on the picks list of fields.

Limit the foreach scope like this:
Code:
foreach pick in hero from BaseClHelp where "TagGroup.Tag"
or 
foreach pick in hero from BaseClHelp
Always better to use a tag then any field for searching. HL is optimized to deal with Tags not so much with fields. By saying "from BaseClHelp" we are limiting HL down to just the Class Helper Picks on the hero which will be ALLOT smaller subset of Picks to deal with then every Pick.

Please note I can't remember if BaseClHelp is correct for d20 as I am not near HL. You can see which "Components" make up a Pick by looking at its tags and the 'component.?' group section.
I don't think BaseClHelp is correct for where we want to look, but I have no idea where to find the right term let alone what it would be.

Again, I'm not familiar enough with the structure of foreach, and how they are handled in the system. For my initial endeavor on this project I wanted to limit the scope to only the first 20 "class" entries. The likely components would be BaseClass, BaseRace, or BaseTemp. If there are others I have not noticed them yet. My concern is that if I set it up for those components it would run through all the class levels (out to theoretically 100), pulling information that it should not.

The other question is what order do foreach loops approach data? I would assume following an index somewhere, but then the question goes, could classes end up on the search index in a different order then their class index on the hero? For example, could a hero's 30th class level end up being searched before their 3rd class level.

I suppose I could restructure it as:
Code:
foreach pick in hero from BaseClHelp
if (eachpick.field[cIndex].value = 1) then
....
elseif (eachpick.field[cIndex].value = 2) then
etc...
and in this way limit the search and get the data saved to variables depending on the index value, for use in later calculations. I still think it would be better if we could find a way to remove the foreach and search on class index.

By the way, if the first foreach bothers you, the next 6 all have a duplicate structure to each other. More then the first, I feel that those should be able to be replaced since the class helpers are part of an array, but again, I've only dealt with array values in script by using the copy/paste approach.
Nightfox is offline   #19 Reply With Quote