Function

Forgewright
06 Sept 2018, 04:12

It was my understanding that a variable created in a script could not be carried over to a function when called in that same script. Hope that makes sense.

I was looking at the DoTake function and see the object being taken is referenced several times.

if (HasScript(object, "ontake")) {
      do (object, "ontake")
    }
    if (found and GetBoolean (object, "scenery") and object.parent = game.pov) {
      object.scenery = false

How does the function know what object is being referenced?
I have been gone awhile and need some refreshing.


mrangel
06 Sept 2018, 06:00

object is one of the function's parameters.


Nakita Block
08 Sept 2018, 20:20

A variable can't be carried over, but an object's parameters can because they're a part of the object itself. So I've learned if I'm going to need a global variable, I will create an invisible object named "temp" and use its parameters as variables to carry over to other areas of the game.


mrangel
08 Sept 2018, 22:51

I think you mean "attributes". An object has attributes; a function has parameters.
Rather than creating an invisible object, it's common to use attributes of the game element itself.

However, I would suggest using actual parameters wherever possible. This is what they're designed for, after all, and makes it easier to keep your code organised.