Jump to content

My array is skipping certain indexes?


Recommended Posts

I have the following code:

 

 

int Function ReturnFromFormlist(Armor targetArmor)

 

int mIndex = rc_Formlists.GetSize()
string mName = targetArmor.GetName()     ;I have verified that this sets properly. Wearing daedric armor, this becomes "Daedric Armor"

string [] nameArray
nameArray = new string[30]

bool tmpBool = NameLoop(StringUtil.GetLength(mName) - 1, mName, nameArray)
;The -1 is to account for Arrays starting at 0 while the GetLength function counts from 1.

return 0
EndFunction




int Function NameLoop(int mLength, string mName, string[] nameArray)

while mLength > 0
nameArray[mLength] = StringUtil.GetNthChar(mName, mLength)
Debug.Notification(mLength)
Debug.Notification(nameArray[mLength])


mLength -= 1
endwhile

return 1
EndFunction

 

 

 

 

I have a key set up to trigger this when pressed.

When I trigger it, I get Debug notifications just as one would expect, but Debug.Notification seems to treat the values at Index 4 and 9 as if they don't exist.

 

With targetArmor as a Daedric Armor, I get the following output at the following Indexes:

 

0 D

1 A

2 E

3 D

4 -Nothing, not even a blank space-

5 I

6 C

7 (Blank Space)

8 A

9 -Nothing, not even a blank space-

10 M

11 O

12 R

 

I can't even determine if it is Index 4 and 9 that don't get set when they should or if it's Debug.Notification that is showing their values improperly.

This is an integral part of the mod I'm working on at the moment, and I can't move on without it.

 

Any help would be greatly appreciated at this point.

Link to comment

In the second function move the

 

mLength -= 1

 

just after the while, and not at the end of it.

I assume this is what you mean:

 

while mLength > 0

mLength -= 1

nameArray[mLength] = StringUtil.GetNthChar(mName, mLength)

Debug.Notification(mLength)

Debug.Notification(nameArray[mLength])

endwhile

 

 

This did not work.

Link to comment

Try this:

 
Function Test(Armor targetArmor)
  string mName = targetArmor.GetName()
  string [] nameArray = new string[30]
 
  NameLoop(mName, nameArray)

  Debug.trace("Final: " + nameArray)
EndFunction
 
 
Function NameLoop(string mName, string[] nameArray)
 
  int i = 0
  int len = StringUtil.GetLength(mName)
  while i < len
    nameArray[i] = StringUtil.GetNthChar(mName, i)
    Debug.trace("Position " + i + " got *" + nameArray[i] + "*")
    i+=1
  endwhile
EndFunction

Check the result in your papyrus log.

Link to comment

This works according to the log.

 

[03/14/2017 - 06:26:28PM] Position 0 got *D*
[03/14/2017 - 06:26:28PM] Position 1 got *A*
[03/14/2017 - 06:26:28PM] Position 2 got *E*
[03/14/2017 - 06:26:28PM] Position 3 got *D*
[03/14/2017 - 06:26:28PM] Position 4 got *R*
[03/14/2017 - 06:26:28PM] Position 5 got *i*
[03/14/2017 - 06:26:28PM] Position 6 got *C*
[03/14/2017 - 06:26:28PM] Position 7 got * *
[03/14/2017 - 06:26:28PM] Position 8 got *A*
[03/14/2017 - 06:26:28PM] Position 9 got *R*
[03/14/2017 - 06:26:28PM] Position 10 got *M*
[03/14/2017 - 06:26:28PM] Position 11 got *O*
[03/14/2017 - 06:26:28PM] Position 12 got *R*

 

 

Debug.Notification() still skips over every 5th entry in the index however, so it seems the issue really is with Debug.Notification() not giving reliable feedback.

It's no issue to my project since I was just using it for testing, but it's good to know that Debug.Notification() is unreliable for checking values in an array.

Wish that was written down somewhere so I didn't have to spend all day tearing my hair out over code that apparently works anyway.

 

While I have you ear, could you possibly tell from just looking if this code would be overly demanding on papyrus?

What if it ran 20 times in succession? Would it be too taxing for your average user?

Link to comment

I just don't understand what you are trying to do with this code.

 

I can see that you are trying to split a string in single letters.

It is not really heavy, but I don't understand why you wanna do it.

Link to comment

I just don't understand what you are trying to do with this code.

 

I can see that you are trying to split a string in single letters.

It is not really heavy, but I don't understand why you wanna do it.

Might as well share since I intend to release the final mod publicly anyway.

 

The mod I'm working on is a system that would allow the equipment of armor variants.

I plan to achieve this by adding ArmorAddons with variants of the selected armor to the armor, then setting the model path of the armor's active ArmorAddon to the model path of your desired variant.

 

"This has the issue that all armors share this setting, so all copies of the same armor will look the same!"

My solution: A secondary system!

 

I have a master-formlist that contains a bunch of other formlists.

The formlists within this master-formlist are named after all compatible armors.

 

For example, since I have made "Daedric Armor variants" that make the Daedric Armor compatible with the system, I have made a Formlist that is named "DaedricArmor" and added it to the master-formlist.

(The base mod contains no armors, they are added through plugins. Some of which I'll provide.)

 

Then I take the "Daedric Armor" object in the CK and duplicate it as many times as I have decided that my system will handle. (Arbitrarily set to 20 for now)

 

Add these 20 Daedric Armor forms into the DaedricArmor formlist.

 

Whenever an armor is set to become a variant by anyone in the game, be it the PC or an NPC, it will be swapped out for an identical copy of it from the corresponding formlist. (This has already been achieved by another modder who goes by Raestloz, whose code I'm adapting for my system.)

 

Only issue I haven't solved in theory is that the armors that come pre-enchanted in skyrim aren't compatible, but player/mod enchanted and improved armors are.

 

 

 

And to answer your question of what I need this particular code for:

Since Formlist names can't have spaces in them, and my "find formlist in master-formlist that corresponds to the armor" function is forced to be based on the name of the armor(Because the CK is a bitch like that), I need a system to weed out the spaces in armor names in order for the search function to work.

 

I believe that should cover it.

Kind of a long post, but hey. You asked. ^^

Link to comment

Mh, OK.

Trying to match item by names and substrings probably is not really a good idea for a couple of raesons:

1) It is inefficient

2) How will you handle localizations?

 

If I understood you correctly, in case an Actor gets an "Armor" you want to replace it with a "Variant".

 

So technically you just need a way to group the armors of the same type together (the armors that are a variant of a basic one.)

A form list is not bad for it, just use custom formlists.

 

Then if you need to pick an armor randomly just convert the content of the form list into an array, and get a random item by index (and check if the index is exactly the index of the armor to be varied, so you don't replace an armor with itself.)

 

You don't really need string manipulation.

Link to comment

Mh, OK.

Trying to match item by names and substrings probably is not really a good idea for a couple of raesons:

1) It is inefficient

2) How will you handle localizations?

 

If I understood you correctly, in case an Actor gets an "Armor" you want to replace it with a "Variant".

 

So technically you just need a way to group the armors of the same type together (the armors that are a variant of a basic one.)

A form list is not bad for it, just use custom formlists.

 

Then if you need to pick an armor randomly just convert the content of the form list into an array, and get a random item by index (and check if the index is exactly the index of the armor to be varied, so you don't replace an armor with itself.)

 

You don't really need string manipulation.

 

I realize in hindsight that I misspoke in my last post. The player's armor won't be handled like the NPC's. This is important.

 

Replacing the armor item technically has nothing to do with the variant system.

The "variants" of each armor are just ArmorAddons that will be added to the corresponding armor when it is made compatible.

 

For example, the armor "Iron Armor" in vanilla contains just an ArmorAddon that points at the vanilla Iron Armor nif.

A compatible armor in my system will have multiple ArmorAddons added to it, each pointing to their own nif file containing a variation of the base armor.

 

The ArmorAddon at the top of the order is by default the active ArmorAddon that you see in the game world.

System 1 will set ArmorAddon 1's model path to the model path of one of the other ArmorAddons beneath it, depending on the chosen variant.

System 1 has nothing to do with the master-formlist that contains the list of the duplicate armors.

 

System 2 runs in tandem with System 1.

System 2 is called on when an NPC has their armor set to be a variant.

(This will happen through functions that other mods are supposed to be able to call on when they want to change the PC's or an NPC's armor to be one of it's variations)

When this happens, System 2 will check the name of their armor and find the formlist that it corresponds with in the master-formlist.

Then it will replace the armor with an identical copy from this list of duplicates. Though they are identical, they are separate identical objects rather than linked clones of the base armor. The number of entries in the formlist is the maximum number of a specific armor type that can exist uniquely before it loops back around. 20 copies and entries in the Iron Armor list means that up to 20 unique iron armors can exist in the game before the next iron armor that is added loops back to being a copy of entry 1 in the list.

 

The reason I have to check the master-formlist with strings is that it's the only way for the system to dynamically work with the armors that are duplicates. Other than the armor name, there's no other trait that is common to the duplicates but unique to the specific armor types.

 

 

 

The player's armor will only be replaced once when it is first acquired, from then on all armors of the same type you acquire will always become a copy of the same "duplicated armor" rather than of the basic vanilla armor.

In theory, improvements and mod/PC added enchantments shouldn't be effected, but that's the wonky ground that I haven't gotten to test yet in development.

 

This is surprisingly helpful in clearing up the specifics of my mod in my own head.

Link to comment

I am glad that explaining what you are trying to do was helpful for yourself to clear up your specifications.

 

In case you have any type of coding questions, feel free to continue to ask.

Link to comment

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more information, see our Privacy Policy & Terms of Use