Mattiewagg Posted December 19, 2014 Share Posted December 19, 2014 If I say, have this: Event OnEffectStart(Actor akTarget, Actor akCaster) ;can't recall if those are the proper parameters Is there a difference in efficiency between calling this: akTarget.MoveTo(akCaster)akCaster.MoveTo(akTarget); yes this is nonsense functions it's hypotheticalakCaster.Kill()akTarget.Kill() And calling this instead: Actor target = akTargetActor caster = akCaster target.MoveTo(caster)caster.MoveTo(target)caster.Kill()target.Kill() So basically what I'm asking - is there a difference in efficiency between using parameters in a script and assigning a variable to a parameter and then using that variable? Link to comment Share on other sites More sharing options...
steelfeathers Posted December 19, 2014 Share Posted December 19, 2014 If there is a performance difference, it isn't noticable as far as I've seen. I usually just assign the parameter to a variable for form's sake. But if anyone here is a scripting expert, feel free to correct me if I'm wrong. Link to comment Share on other sites More sharing options...
lofgren Posted December 19, 2014 Share Posted December 19, 2014 A parameter is just a variable that gets assigned by an outside source, so my question is why would you assign it to another variable? It's just an unnecessary operation, unless of course you need to use that variable again elsewhere in your script. Of course it takes up more resources to assign a parameter to a variable. Every operation you do requires more resources than if you didn't do it. But the resource drain is pitifully small, certainly not noticeable to any human frame of reference. Is it best practice? No. Is it that big a deal? Nah. If it makes you feel better for some reason, go ahead and do it. Of course if you declare the variable outside of the function and you assign an object reference or actor to it, make sure you clear it or you might make the object persistent in certain situations. Link to comment Share on other sites More sharing options...
Mattiewagg Posted December 19, 2014 Author Share Posted December 19, 2014 A parameter is just a variable that gets assigned by an outside source, so my question is why would you assign it to another variable? It's just an unnecessary operation, unless of course you need to use that variable again elsewhere in your script. Of course it takes up more resources to assign a parameter to a variable. Every operation you do requires more resources than if you didn't do it. But the resource drain is pitifully small, certainly not noticeable to any human frame of reference. Is it best practice? No. Is it that big a deal? Nah. If it makes you feel better for some reason, go ahead and do it. Of course if you declare the variable outside of the function and you assign an object reference or actor to it, make sure you clear it or you might make the object persistent in certain situations.I don't do it, just noticed some people do and it made me curious. Thanks for rhe answer. Link to comment Share on other sites More sharing options...
cdcooley Posted December 19, 2014 Share Posted December 19, 2014 I blame that style of excessive variable declaration on introductory programming textbooks. Many sample programs for beginners are filled with redundant variables. I suspect it is so that every little step of the algorithm can be documented. Unfortunately, first impressions are lasting. As lofgren said, function parameters are variables, they just get declared inside those parentheses instead of after them. The values they contain were already copied once when the function was called, so making new local variables and copying them again is just a waste of resources. Some people might be doing it to give those arguments friendlier names, but if you don't like names like akTarget just declare the function with names of your choice. I prefer the less cluttered "Event OnEffectStart(Actor target, Actor caster)" myself. Link to comment Share on other sites More sharing options...
Recommended Posts