• 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

Why Can't Foreach Loops be Used in Creation Scripts?

sincla

Well-known member
The following code:

Code:
 <creation><![CDATA[
              var level as number
	      foreach pick in hero where "ClassLevel.?"
	         level += eachpick.tagvalue[ClassLevel.?]
	         nexteach
              level += 1
	      perform this.assignstr["ClassLevel." & level]
	      ]]></creation>

gave me the following error:

Syntax error in 'creation' script for Component 'Class' on line 3
--> Reference to undeclared variable: foreach
 
Last edited:
Code:
  foreach pick in hero from component where "the tags"

Look at your script, it's missing something...
 
I added in the component:

Code:
foreach pick in hero from Class where "ClassLevel.?"

and I get the same error.

I didn't know the from Component was required. The wiki example doesn't have it:

Code:
foreach pick in hero where "group.tag"
            debug "id: " & eachpick.idstring
            nexteach

and I've succesfully executed foreach loops without it, even in the skeleton code there are examples such as:

Code:
foreach pick in hero where "system_tag.minion"

Was that not what you were getting at? Did I totally miss your point?
 
Usually specifying the component is important, otherwise you're searching through all the picks on the actor having the tag...

I'd say lookup foreach context in the kitwiki and read it. I'm not sure if you can use a foreach loop during a creation script, as you usually set field limitations and default user values with a creation script. I think creation scripts are for preadvancement phase characters. Once a character is locked for advancement those scripts are done running.

What are you trying to do specifically with your foreach loop? What are you trying to tell the compiler to do?
 
Oh this is just one of my convoluted schemes to try and get sequential ordering of the class rows in the level column of the class level table like the d20 system. I was trying to make class picks not unique, give each one a separate level tag for the character level at which it was added, and display that in the level portal of the table dynamic.

To be completely clear about the ultimate goal, I've attached a screenshot. I hope it's helpful.
 

Attachments

  • level ordering.jpg
    level ordering.jpg
    56.1 KB · Views: 7
Table Dynamic Element in the wiki

look for:
orderfield=""

You don't need a foreach loop for that...
 
Thank you. I feel chastened once again that it was something with a dedicated feature I was overlooking.

It took me awhile to figure out, its not so easy to figure out honestly. I've had to ask for help many times.
 
Back
Top