• 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

Adding new rows to an array.

Redcap's Corner

Well-known member
If I want to create an ability that has an array-based menu with options that get more numerous as the character levels up, where should I start? Is there an ability people know about that does this already that I could use as a template?

I tried starting with an array that contained a row 0 and a row 1, and I tried using the following code nested in an if-then statement that checked to see whether the character was a certain level yet:

Code:
field[usrArray].arraytext[2] = "New Option"

And that didn't work. I've dug around and I understand that I can refer to the selected text using field[usrSelect].text and the selected row using field[usrIndex].value but how do I actually add rows?
 
That seems like it should work. Is the eval script running on the same pick that has the array? What timing is your script running at?

For an example of something filling in an array, check out the Dragon Ferocity feat, which creates an array on Elemental Fist.
 
I don't see anything wrong with your line of code, Redcap, so I suspect the problem in your script isn't in that line of code - exactly what error message are you getting, and what's the context of that (and the phase & priority).

AndrewD2 - arraytext[] is for text arrays and arrayvalue[] is for numerical arrays. The array for the drop-down menu is a text array.
 
The eval script is running on the same pick that has the array. I'm not getting an error message. It just isn't working. It has to be a timing issue if the code looks okay to you guys. I'll check out Dragon Ferocity and post my solution in here if I work it out.
 
All right, I got this working (at post-attributes/4000), but now I'm getting an error trying to make the array useful. Because I'm anal, I'm trying to keep the array in alphabetical order even though the user's options are not gained in alphabetical order. Thus, every time new options are gained, I'm changing the text of the old rows AND adding new rows. So, in my efforts to have the user's choice actually do something, I'm trying to check the text of their choice, not the row number. I'm using the following code:

Code:
if (field[usrSelect].text = "Diminutive") then

And getting "Error parsing right-side expression in relational comparison". Is using usrSelect in this way not possible?
 
You can use the compare() function to check two different strings against each other, but it's computationally expensive so we discourage its use if it can be avoided.

Code:
          if (compare(field[usrSelect].text, "Diminutive") <> 0) then
            ~ Do whatever
            endif
 
How many nested if-thens does it take before compare becomes the more efficient option? (: I can accomplish what I want to do using row numbers, but it's going to take a lot of nesting.
 
"Compare" is working in that I'm no longer getting an error message. Unfortunately, using the following (abridged for readability) code, the result always acts as though compare(field[usrSelect].text, "Diminutive") = 1, regardless of what the user actually selects.

Code:
if (field[usrIsCheck].value <> 0) then
  if (compare(field[usrSelect].text, "Diminutive") <> 0) then
    ...
  elseif (compare(field[usrSelect].text, "Tiny") <> 0) then
    ...
  elseif (compare(field[usrSelect].text, "Small") <> 0) then
    ...
  elseif (compare(field[usrSelect].text, "Medium") <> 0) then
    ...
  elseif (compare(field[usrSelect].text, "Large") <> 0) then
    ...
  elseif (compare(field[usrSelect].text, "Huge") <> 0) then
    ...
    endif
  endif

At the level I'm currently testing, "Diminutive" isn't even one of the available options, so maybe that's part of the issue. The above is running at first/20000 and the below, running at first/500, is setting the options in the array. I'm testing at 6th level, and I have tested that the below code works before and after 6th, as well as after 8th.

Code:
if (root.field[cTotalLev].value >= 8) then
  field[usrArray].arraytext[0] = "Diminutive"
  field[usrArray].arraytext[1] = "Tiny"
  field[usrArray].arraytext[2] = "Small"
  field[usrArray].arraytext[3] = "Medium"
  field[usrArray].arraytext[4] = "Large"
  field[usrArray].arraytext[5] = "Huge"
elseif (root.field[cTotalLev].value >= 6) then
  field[usrArray].arraytext[0] = "Tiny"
  field[usrArray].arraytext[1] = "Small"
  field[usrArray].arraytext[2] = "Medium"
  field[usrArray].arraytext[3] = "Large"
  endif
 
Okay, I just upped my test hero to 8th level, at which point selecting "Diminutive" yields the results I would expect for "Tiny". Is it possible that "0" means true when using compare?
 
Sure enough. I replaced "<> 0" with "= 0" in all my compare statements and now it works perfectly. Apparently compare returns false if its components do match.
 
Back
Top