Skip to reading
PCA Script Programming

27. This, the caller and the active player

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page
Code example
function run()
    if this == null
        warn("This script needs an object caller.")
        return false
    end
    log("Called by " + str(this.id))
    return true
end

this means the object or record that called the script, when the call supplied an owner. It does not mean whichever object is selected in the editor. A direct Run button or global event can have no owner, so check for null in reusable code.

player resolves the active player. A function called by a door can therefore use this for the door and

player for the actor standing in front of it. Capture an ID before a delayed operation if later player switching would change what you intend to address.

A shared GUI element action may also use special caller IDs such as this in the action’s own fields. That is context routing, not proof that a GUI element is a direct PCA namespace record. Use guiId and elementId from the event/context when you need a particular element.

A nested call normally inherits caller context through the router. If you supply a new context dictionary, preserve the keys your helper needs. The phrase “this script” is not the same as the language value this.

Page 35 of 357Permalink
Go to page