• 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

Complicated foreach statement/variable interaction.

Redcap's Corner

Well-known member
The class I'm working on has an ability that allows it to use two polymorph effects simultaneously, taking the better of each physical ability score modification, summing the natural armour bonuses of both, and taking the size category of either. Many of the questions I've been asking over the last week or two have been leading up to this particular nightmare. I've come up with the following code to start this ability out.

Code:
FIRST/20001
~ If the hero doesn't have this ability, ignore the following.
doneif (tagis[Helper.ShowSpec] = 0)

~ Determine the hero's polymorph effects and flag them to work with Polymeld.
foreach pick in hero where "Custom.NoPolymeld"
  perform eachpick.delete[Custom.NoPolymeld]
  nexteach

~ Determine which two polymorph effects are active.
var polycount as number
var polymorph1 as string
var polymorph2 as string
foreach pick in hero where "Custom.ActivePoly"
  if (polycount = 0) then
    if (eachpick.field[usrIsCheck].value <> 0) then
      polymorph1 = eachpick.idstring
      polycount += 1
      endif
  elseif (polycount = 1) then
    if (eachpick.field[usrIsCheck].value <> 0) then
      polymorph2 = eachpick.idstring
      polycount += 1
      endif
    endif
  nexteach

~ Set the hero's modifiers.
hero.child[aSTR].field[aStartMod].value += maximum(polymorph1.field[abValue].value, polymorph2.field[abValue].value)
hero.child[aDEX].field[aStartMod].value += maximum(polymorph1.field[abValue2].value, polymorph2.field[abValue2].value)
hero.child[aCON].field[aStartMod].value += maximum(polymorph1.field[abValue3].value, polymorph2.field[abValue3].value)
hero.child[ArmorClass].field[tACNatural].value += polymorph1.field[abValue4].value + polymorph2.field[abValue4].value

The error I'm getting is for the line where I attempt to set the attributes, and it says "Error parsing parameter 1 of function". My guess is that it doesn't like my using a variable as only part of the address of a field. Is that correct? If I get the variable to hold the entirety of the address, will it like it better?

Further, I'm going off the assumption that my looping tricks from my QBasic days in middle school will work with foreach statements, but I guess I don't know for sure. With a foreach statement, the code cycles through each match one at a time, allowing me to flag results the way I'm attempting, right? Is there a better way of doing this?

And for reference, here is an example of one of the abilities its drawing from (they all have similar code).

Code:
FIRST/20000
~ Determine the size modifiers for the chosen size category.
var sizetarget as number
if (field[usrIndex].value = 0) then
  field[abValue].value = 4
  field[abValue3].value = 2
  field[abValue4].value = 4
  sizetarget = 0
elseif (field[usrIndex].value = 1) then
  field[abValue].value = 6
  field[abValue3].value = 4
  field[abValue4].value = 6
  sizetarget = 1
elseif (field[usrIndex].value = 2) then
  field[abValue].value = 10
  field[abValue3].value = 8
  field[abValue4].value = 8
  sizetarget = 2
  endif

~ If polymeld is overwriting this ability, ignore the following.
doneif (tagis[Custom.NoPolymeld] = 0)

~ If this ability hasn't been activated, ignore the following.
doneif (field[usrIsCheck].value = 0)

~ Set the hero's size category and modifiers.
hero.child[aSTR].field[aStartMod].value += field[abValue].value
hero.child[aCON].field[aStartMod].value += field[abValue3].value
hero.child[ArmorClass].field[tACNatural].value += field[abValue4].value
call SetSizeTo

This obviously isn't complete. I still need to setup a size category menu on the Polymeld ability to allow the user to select the size category of their final form. And I need to have each polymorph ability disable each of the others when selected UNTIL polymeld comes online, at which point I need to have each pair of polymorph effects disable each of the others. I believe what I've currently written is enough to get the basic kinks hammered out, though.
 
Last edited:
That being the case, I've been forced to actually use my brain, and I've come up with much more streamlined code:

Code:
FIRST/19999
~ If the hero doesn't have this ability, ignore the following.
doneif (tagis[Helper.ShowSpec] = 0)

~ Determine the hero's polymorph effects and flag them to work with Polymeld.
foreach pick in hero where "Custom.NoPolymeld"
  perform eachpick.delete[Custom.NoPolymeld]
  nexteach

~ Determine the active polymorph effects.
var strcheck as number
var dexcheck as number
var concheck as number
var nacheck as number
foreach pick in hero where "Custom.ActivePoly"
  if (eachpick.field[usrIsCheck].value <> 0) then
    strcheck = maximum(strcheck, eachpick.field[abValue].value)
    dexcheck = maximum(dexcheck, eachpick.field[abValue2].value)
    concheck = maximum(concheck, eachpick.field[abValue3].value)
    nacheck += eachpick.field[abValue4].value
    endif
  nexteach

~ Set the hero's modifiers.
hero.child[aSTR].field[aStartMod].value += strcheck
hero.child[aDEX].field[aStartMod].value += dexcheck
hero.child[aCON].field[aStartMod].value += concheck
hero.child[ArmorClass].field[tACNatural].value += nacheck

The issue is that this code doesn't seem to be actually deleting the Custom.NoPolymeld tag from anything. It occurred to me that this code actually needs to run before, not after the code for the individual polymorph effects, so that Custom.NoPolymeld has been deleted before those effects look for it. I've moved it to First/19999. I can't for the life of me figure out what's wrong with the code that's supposed to delete Custom.NoPolymeld from everything, though.

I appreciate everyone on this board bearing with me! I'm sure you can all tell my understanding of what I'm doing has developed significantly over the past few weeks, and I promise that for every problem I post here, I solve ten on my own. The material I'm working on is being coded for playtesting for eventual publication through the store I own, so I want to make sure I'm getting it all right.
 
Actually, now that I think about it, only the code that deletes Custom.NoPolymeld needs to run before the individual polymorph effects. In fact, the rest of the code needs to run afterward. I'll have to split this into two different scripts.
 
It appears the offending piece of code is actually:

Code:
doneif (tagis[Helper.ShowSpec] = 0)

Does this not mean what I think it means? Helper.ShowSpec is a tag that an ability gets when the hero is the appropriate level to gain that ability, right? And tagis checks whether the pick has the appropriate tag? And 0 means false? And doneif means "if [condition], then ignore the rest of this script"? Shouldn't this mean "if the hero doesn't have this ability, ignore the rest of this script"?
 
Helper.ShowSpec is not added until Post-Levels/300 - it means that this class special has reached the correct level, and there's no archetype that's replaced the ability.
 
Ooooh! Of course. It's the same issue I had before. I'm trying to check if the class is high enough level before the levels have been applied. I'll have to use the sneaky backdoor way of checking. Thanks again!
 
Back
Top