z-edit / zedit

An integrated development environment for Bethesda Plugin Files.
https://z-edit.github.io
MIT License
304 stars 56 forks source link

xelib.GetElements(record, "Effects", false) returns zEdit functions list after effect numbers #261

Closed TokcDK closed 2 years ago

TokcDK commented 2 years ago

Tried this patcher and got there errors for some spells.

Then put try catch and some debug output info and form log understood this line returns for some spells in Skyrim LE not only effect numbers but also function names and because patcher was failed on some spells. Example log after I put try catch and debug output for each i in effects in lines starting with "Checking":

Loading Spell records from Skyrim.esm.
Filtering 826 Spell records from Skyrim.esm
Processing spell dunTransmogrifySpell "Безобидное превращение" [SPEL:001092A2]
effects length is 1
Checking 0
Checking unite
Checking random
Checking getIndex
Checking remove
Checking contains
Checking subtract
Checking findByKey
Checking sortOnKey
Checking filterOnKey
Checking mapOnKey
Checking joinOnKey
Checking unique
Checking joinList
Checking groupBy
Checking forEachReverse
Checking forEachNested
Checking findMapping
Checking trimFalsy
Checking last
Checking findNested
Checking itemsBefore
Checking itemsAfter
Checking insertAfter
Checking insertBefore
Checking partition
Processing spell DA16RitualSpell "Вызов портала" [SPEL:000C3EC0]
effects length is 1
Checking 0
Checking unite
Checking random
Checking getIndex
Checking remove
Checking contains
Checking subtract
Checking findByKey
Checking sortOnKey
Checking filterOnKey
Checking mapOnKey
Checking joinOnKey
Checking unique
Checking joinList
Checking groupBy
Checking forEachReverse
Checking forEachNested
Checking findMapping
Checking trimFalsy
Checking last
Checking findNested
Checking itemsBefore
Checking itemsAfter
Checking insertAfter
Checking insertBefore
Checking partition
Processing spell dunTrevasSpectralArrow "Призрачная стрела" [SPEL:000AB23D]
effects length is 2
Checking 0
Checking 1
Checking unite
Checking random
Checking getIndex
Checking remove
Checking contains
Checking subtract
Checking findByKey
Checking sortOnKey
Checking filterOnKey
Checking mapOnKey
Checking joinOnKey
Checking unique
Checking joinList
Checking groupBy
Checking forEachReverse
Checking forEachNested
Checking findMapping
Checking trimFalsy
Checking last
Checking findNested
Checking itemsBefore
Checking itemsAfter
Checking insertAfter
Checking insertBefore
Checking partition

I fixed the error with if (isNaN(i)) and maybe there is incorrect GetElements use but there is other functions list from here and below. I noticed that Length is displaying correct count and it can be fixed by use length but it still strange if effects elements returning function names after effect numbers. Noticed your fork and will use it but it still strange that 'for..in' returns function names.

matortheeternal commented 2 years ago

so the correct way to iterate over an array in javascript is for..of, not for..in. that code is iterating over properties and isn't even doing a hasOwnProperty check so it's looking at prototype properties as well. So it's iterating over every function supported by Array.prototype. The functions here aren't zEdit functions, they're array extensions in the zEdit codebase.

Just use the fork.