Difference between revisions of "Talk:Add - Array"
m
no edit summary
imported>Goggle |
imported>LAITH10 m |
||
Line 5: | Line 5: | ||
I haven't tested it on non-property arrays thought. | I haven't tested it on non-property arrays thought. | ||
: This function does work for non-property arrays. I've used the method myself. My only problem with that is, add expands the array, which isn't always what one wants to happen, you'd need a way to clamp it if is used in a while loop.--[[User:Twilight Sky|Twilight Sky]] ([[User talk:Twilight Sky|talk]]) 2016-09-25T08:12:34 (EDT) | : This function does work for non-property arrays. I've used the method myself. My only problem with that is, add expands the array, which isn't always what one wants to happen, you'd need a way to clamp it if is used in a while loop.--[[User:Twilight Sky|Twilight Sky]] ([[User talk:Twilight Sky|talk]]) 2016-09-25T08:12:34 (EDT) | ||
After some further testing I found the issue: If you have a property array, you have to make sure that it is either assigned a value via CK, or initialise it somewhere in the code (preferably in OnInit()). If you do not initialise the array via CK with at least one element, the array will be none and thus no functions such as Add() will work. | |||
I had assumed that CK would do that automatically, given that you cannot use the new command during a declaration of a property. Thus I highly suggest to check the array and initialize it if needed somewhere in the code such as: | |||
<source lang="papyrus"> | |||
event OnInit() | |||
if !MyArray | |||
MyArray= New MyArrayType[0] | |||
endif | |||
endevent | |||
</source> | |||
This makes sure that the array is initialized, but still without any elements. Now the array is working as intended. | |||
Likewise, the same issue appears with non-property arrays if you did not initialize it before. | |||
I would recommend to put this information somewhere on the array articles, as this can lead to some serious problems. It got me a good headache just to find that issue. [[User:Shirakami|Shirakami]] ([[User talk:Shirakami|talk]]) 2016-09-25T09:20:53 (EDT) |