How many function calls is too many?

Post » Tue Mar 04, 2014 4:48 am

Question directed mostly to programmers / advanced scripters

Would calling simple function multiple times (15 or more from different scripts) at the same time (but just once, without polling):

Int Function HookController(Actor akActor)      Return myArray.Find(akActor)EndFunction

be bad programming? Should I avoid such sitations at all cost?

I havent seen similar thing in "user made" functions, but if I think about some native functions like - Is3DLoaded, IsRunning then they could be spammed theoretically without feeling wrong.

When I call my own function like that I just feel bad. :(

User avatar
sharon
 
Posts: 3449
Joined: Wed Nov 22, 2006 4:59 am

Post » Tue Mar 04, 2014 1:07 pm

Shouldn't really be a big deal in the example you posted, just keep in mind that all those 15 functions will have to wait for one another in the queried script's thread queue. For a simple find function like you posted I can't imagine it having a very noticeable speed impact though.

If you are doing something more involved that only requires reading from that array, you could also set up a pointer to the same array as a local variable or as a property in your other scripts. Something like

Spoiler
MainScript property Mothership autoActor[] property myArrayPtr auto hiddenFunction Setup()    myArrayPtr = Mothership.targetArrayEndFunctionFunction YourFunction()    ;...    int i = myArrayPtr.find(akActor)    ;...EndFunction

This array will always point to the same array as in the main script, even if it changes. I use a setup similar to this across about a dozen scripts in one of my mods and it works well. You would just have to be careful you don't have any situation where multiple scripts would be trying to edit the same array.

Another option, which might not work well for this specific case, but in general when it comes to making many calls to a function, is to broadcast a mod event instead, which all your scripts can respond to individually. You can't pass an array via mod event, but most other types of variables should now be possible with the latest build of SKSE.

User avatar
Beast Attire
 
Posts: 3456
Joined: Tue Oct 09, 2007 5:33 am


Return to V - Skyrim