View Single Post
Mathias
Senior Member
Lone Wolf Staff
 
Join Date: May 2005
Posts: 13,213

Old June 17th, 2012, 04:16 PM
Special Transitions: Searching

Often, you don't know exactly what child you want to transition to, but you know some things about what it will be like. For example "I want to find a light weapon that deals piercing damage and is made of metal". Other times, you know there are multiple picks with the same Id. The child[] transition would only take you to one of them, and it would pick that one at random, so, you need a way to find all of them. That's handled by searching through a container to find those picks.

Code:
 
foreach pick in container from component where "test expression"
  nexteach
Replace container with either hero or gizmo. To use gizmo, you'll need to be starting in a pick that has a gizmo, or set up some set of transitions that ends in gizmo.

In that, replace component with the Id of a component that all of the things you're searching for have in common. To find this, add some examples of a few of the things you're trying to find to a test character, and look at their tags. There will be a section of tags whose Group Ids are all "component". Pick one of these - one that all of the things you're looking for will have.

Replace test expression with a tag expression that narrows down the list even further than just the component does. To find these tags, look at the tags on the example items you added, and compare them to the tags on things that are like those examples, but not quite.

If just the component will do the trick and will identify all the things you're searching for, you can leave out 'where "text expression"' entirely.

While you're in that foreach, you can use a special transition:
  • eachpick
    • Travels to the pick context that's currently being worked on
Remember that if you don't use the eachpick transition, you're still in the default place for this script, and from there, you can go to all the places you normally would, and do all the things you normally would.

An example:

Code:
 
foreach pick in hero from BaseSkill where "Helper.ClassSkill"
  eachpick.field[Bonus].value += 1
  nexteach
That will search through all the picks in the hero container that have the BaseSkill component and have the Helper.ClassSkill tag.

On each of the picks it finds, it will travel to the Bonus field for that pick, and add 1 to its value. In other words; "All our class skills get +1".


Once you're done with all the operations that apply to the things you're searching for, close your foreach with the following line:
Code:
 
nexteach
Sometimes, you know there will only be exactly one thing that matches what you're searching for (for example, you know that a character will have a single race, but you don't know which race the user will actually pick).

This is a special transition you can do from either the hero or gizmo contexts:

findchild[component,test expression]

component is the same as in a foreach, and test expression is also the same as in a foreach. As in a foreach, if you don't need an expression, you can leave it out (if you do, leave out the comma, too).

It's very common to use the setfocus instruction after findchild[] - that way, you don't need to repeat the search if there are lots of questions you want to ask on that pick and/or many things to change. Think of it as findchild[component,test expression].setfocus

Last edited by Mathias; June 17th, 2012 at 06:26 PM.
Mathias is offline   #7 Reply With Quote