Difference between revisions of "Talk:Arrays (Papyrus)"

Jump to navigation Jump to search
2 bytes removed ,  12:59, 13 April 2015
no edit summary
imported>Five Alpha Reductase
imported>Five Alpha Reductase
Line 255: Line 255:
--[[User:JaxFirehart|JaxFirehart]] ([[User talk:JaxFirehart|talk]]) 16:41, 30 August 2012 (EDT)
--[[User:JaxFirehart|JaxFirehart]] ([[User talk:JaxFirehart|talk]]) 16:41, 30 August 2012 (EDT)
::Btw you forgot the last line in your function : ''Return akEquipList''. And yes function parameters are passed by value. Which is somewhat expected considering that the compiler does not allow dynamic arrays (we must provide its absolute length at compile time), more globally does not allow the manipulation of pointers (either to memory addresses and/or function stacks). However, in the context of Papyrus, it's not necessary : all one must do is to declare a variable outside any state, event or function (the default script), which can then be used within any function of the same script, without the need to pass it by address. e.g. in your example, your function could've used playerEquipArray directly instead of declaring a variable local to it (akEquipList), thus using less memory (here doubled) and less processes. Doing this with your other script above would make it work. ''Note that this would require some locking mechanism if you know that another script could externally access that function while it's in use by your script (e.g. the function could return an unexpected playerEquipArray property to your script if it's called at the same time by another script, since the external calls within your function will allow other scripts to unlock the thread - [[Threading_Notes_%28Papyrus%29 | Read more]])''.  --[[User:HawkFest|HawkFest]] ([[User talk:HawkFest|talk]]) 2013-09-09T00:08:38 (EDT)
::Btw you forgot the last line in your function : ''Return akEquipList''. And yes function parameters are passed by value. Which is somewhat expected considering that the compiler does not allow dynamic arrays (we must provide its absolute length at compile time), more globally does not allow the manipulation of pointers (either to memory addresses and/or function stacks). However, in the context of Papyrus, it's not necessary : all one must do is to declare a variable outside any state, event or function (the default script), which can then be used within any function of the same script, without the need to pass it by address. e.g. in your example, your function could've used playerEquipArray directly instead of declaring a variable local to it (akEquipList), thus using less memory (here doubled) and less processes. Doing this with your other script above would make it work. ''Note that this would require some locking mechanism if you know that another script could externally access that function while it's in use by your script (e.g. the function could return an unexpected playerEquipArray property to your script if it's called at the same time by another script, since the external calls within your function will allow other scripts to unlock the thread - [[Threading_Notes_%28Papyrus%29 | Read more]])''.  --[[User:HawkFest|HawkFest]] ([[User talk:HawkFest|talk]]) 2013-09-09T00:08:38 (EDT)
::It may not be necessary, but that doesn't mean it's not useful. Loops aren't necessary either, but try doing any half serious coding without them and you'll be wanting to hang yourself from a tree.


In any case, the explanation in the main page is misleading, since it states that arrays are passed by reference, but as we know this isn't always the case. I had to learn it the hard way.. Anyway, I am editing the article to reflect this information.
::It may not be necessary, but that doesn't mean it's not useful. Loops aren't necessary either, but try doing any half serious coding without them and you'll be wanting to hang yourself from a tree. In any case, the explanation in the main page is misleading, since it states that arrays are passed by reference, but as we know this isn't always the case. I had to learn it the hard way.. Anyway, I am editing the article to reflect this information.--[[User:Five Alpha Reductase|Five Alpha Reductase]] 2015-04-09T00:13:54 (EDT)
--[[User:Five Alpha Reductase|Five Alpha Reductase]] 2015-04-09T00:13:54 (EDT)
= Avoiding "Array Index out of range" =
= Avoiding "Array Index out of range" =


Navigation menu