Function

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.


object is one of the function's parameters.


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.


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.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums