• Please note: In an effort to ensure that all of our users feel welcome on our forums, we’ve updated our forum rules. You can review the updated rules here: http://forums.wolflair.com/showthread.php?t=5528.

    If a fellow Community member is not following the forum rules, please report the post by clicking the Report button (the red yield sign on the left) located on every post. This will notify the moderators directly. If you have any questions about these new rules, please contact support@wolflair.com.

    - The Lone Wolf Development Team

Learning about "foreach"

Bob G

Well-known member
Hi folks, still having a little trouble understanding how to script a foreach loop, and I'm hoping someone can guide me in the right direction.

I'm creating a class ability that selects from a set of rogue talents. I've identified each valid rogue talent with the tag "abCategory.Inh_tal" I then put in the following eval script:
Code:
foreach thing in Ability where "abCategory.Inh_tal"
     field[usrCandid1].text = splice(field[usrCandid1].text, eachthing.tagids[thingid.?], " | ")
      nexteach
I put in a debug into the script to be sure that all applicable talents where being considered as candidates, which correctly identified all candidates.

But on the class tab, the drop-down menu still shows "Nothing to select". What is my script missing?
 
Not sure you are trying to achieve your goal correctly. You probably need to use a candidate expression on said field, not try to muck with values.
 
I assume the issue is that you have the Dropdown setup to use Picks and the Foreach loop is looking at Things. Either change your dropdown to look at Things or change the foreach loop to look at Picks. But currently you have apples looking at oranges and wondering why they don't match. :)

Another way is to take the dropdown out of the equation and do the following:
Code:
foreach thing in Ability where "abCategory.Inh_tal"
  debug eachthing.idstring
nexteach
Then go to Develop->Floating Info Windows->Show Debug Output. This will open a window that will show you the Thing ID from the above Debug statement.
 
Not sure you are trying to achieve your goal correctly. You probably need to use a candidate expression on said field, not try to muck with values.

Hi Minous, I don't think I understand what you mean by a 'candidate expression.' Can you explain a little further?
 
I assume the issue is that you have the Dropdown setup to use Picks and the Foreach loop is looking at Things. Either change your dropdown to look at Things or change the foreach loop to look at Picks. But currently you have apples looking at oranges and wondering why they don't match. :)

Another way is to take the dropdown out of the equation and do the following:
Code:
foreach thing in Ability where "abCategory.Inh_tal"
  debug eachthing.idstring
nexteach
Then go to Develop->Floating Info Windows->Show Debug Output. This will open a window that will show you the Thing ID from the above Debug statement.

Thanks SC, if I take out the dropdown, what do I do with the Thing ID's? How do I get the user to select one from a valid list of 8 different Things?
 
Thanks SC, if I take out the dropdown, what do I do with the Thing ID's? How do I get the user to select one from a valid list of 8 different Things?
I took the name of the thread to heart and thought you where just trying to see how a Foreach loop worked. Not that you where trying to use it for real.

Let’s start over and tell me what you are trying to do/accomplish and then I will have a better chance to answer with the correct way to solve the issue. :)
 
I took the name of the thread to heart and thought you where just trying to see how a Foreach loop worked. Not that you where trying to use it for real.

Let’s start over and tell me what you are trying to do/accomplish and then I will have a better chance to answer with the correct way to solve the issue. :)

Well, you were right. And I'm using it for real. So, both, really :o
I'm creating a class ability that asks the user to select from a menu of rogue talents. One selection, made at first level, and done. Seems easy, but the script I wrote above just doesn't find the right items, even though the debug identified the correct candidates.

Thanks for your help. It's very much appreciated.
 
Well, you were right. And I'm using it for real. So, both, really :o
I'm creating a class ability that asks the user to select from a menu of rogue talents. One selection, made at first level, and done. Seems easy, but the script I wrote above just doesn't find the right items, even though the debug identified the correct candidates.

Thanks for your help. It's very much appreciated.
Lets start with the fact that a Script is NOT able to add new options/Things to a character. I am trying to figure out the purpose of this ability in choosing another ability. Right now you have the foreach reading through THINGS. Things are "Read Only" as they exist in the XML data base and do not exist on a character.

So class ability A selects a rogue talent and then does what? You can't add this rogue talent, you can not change any of its values, and its scripts will not fire because its not a Pick.

To cover your current issue your foreach is reading THINGS and your dropdown is setup to look at PICKS. This is why originally you where getting "Nothing to select". To fix this go into your class ability and on the "Item Selection" section change "Restrict First List To..." to be "All Things".

Now your list you generate will be Things and the dropdown will be Things.

To cover one last idea is that you do NOT need a foreach loop to even build a dropdown list. You can add your own "Custom Expression" and the dropdown is built for you.

For the custom expression simply add this:
Code:
component.Ability & abCategory.Inh_tal
Set the list to All Things and the list is built for you. :)
 
Back
Top