Talk:GetSelf

From GECK
Jump to: navigation, search

GetSelf "preferred"

I have to argue against that one. GetSelf is specifically deprecated, as -- aside from the (admittedly almost inconsequential) overhead in creating a redundant explicit variable -- the GECK (+ Powerup) is designed to spit out errors whenever GetSelf is used in the script of any object that can be carried. GetSelf is useful only in very specific circumstances and it is definitely not preferential to assign explicit ref variables for every act of manipulation when the script is going to be attached to a known reference (or always called from a specific object type with function scripts).

I think anyone should be especially cautious when copying and pasting code, not only because the mere act of doing so increases the likelihood of producing spaghetti code but because it is inappropriate to follow syntax that is only necessary in languages that do not have implied references. Disambiguation is useful when necessary, but unnecessarily time consuming to write and borderline impractical when unnecessary. Designing code for robust copy-paste support is basically asking for it to be misused by people who don't understand what that block of code is doing. The statement that GetSelf should be "prefer[red]" might as well be a suggestion to use more comments instead. ;-)

--JT (talk) 12:36, 13 April 2016 (EDT)

returning 0 when used on a dynamic ref

How was this determined?

Going over some old PMs, I notice I specifically tested for this in '14, running GetSelf in a spell script on a placeatme'd actor, and it returned fine.

I've also never seen GeckPU throw errors over using GetSelf as is mentioned in the last note, and I have many UDFs and effect scripts that use it. (ie : let rActor := GetSelf)

Not sure who was responsible for the 0-return statement. I never saw that behaviour myself either. [edit] Apparently that was Cipscis too, which makes it almost gospel IMO. =)
GetSelf is "dangerous" if used in a GameMode or MenuMode block inside an object script, i.e., an object that can be carried in inventory. I never saw that error myself, however, and was merely trusting that the person who wrote that knew what they were doing (Cipscis) and speaking as to its deprecated status, since I've never used it in any carryable object anyway. Even if really does throw an error, I'm not positive if it performs additional heuristics to validate whether it's attached to an invalid object or whether it would merely validate against the script text.
I simply strongly disagree with Prideslayer's belief that you should create an explicit reference variable filled with GetSelf and then use that reference variable anywhere that an implied reference would be used ordinarily. The justification I recall seeing was that it's dangerous because if you use implied references when copy-pasting code, it may not function as intended. Obviously, copy-pasted code may not function as intended anyway and it's bad practice to copy-paste code unless you know exactly what it's doing, so it's a weak justification and IMO not enough to make a standard of programming.
In any case, UDFs are perfectly safe uses because the call appears in a Function block rather than a GameMode block and UDFs can only ever be called from world objects that are evaluating scripts (i.e., are not inventory objects). GetSelf is likewise more or less mandatory for effect scripts and perfectly valid there too. =) --JT (talk) 02:28, 2 November 2019 (UTC)