Should DoTake() check if object.hasbeenmoved is true before calling object.ontake? [SOLVED]

K.V.
03 Aug 2024, 11:21

Within the script of the DoTake() function, we have this bit of code:

      if (HasScript(object, "ontake")) {
        do (object, "ontake")
      }

Does anyone else think that bit of the script should check if the object was actually taken by checking if object.hasbeenmoved is true before calling the ontake script?

if (HasScript(object, "ontake")) {
  if (object.hasbeenmoved) {
    do (object, "ontake")
  }
}

It is possible (and highly probable) that I am overlooking something, but I feel like this should check if the object was actually taken.


mrangel
03 Aug 2024, 11:33

Checking hasbeenmoved seems kind of irrational; because it doesn't tell you whether the object has actually been taken, just that it has moved at some point. If you added this check, it would mean that the first time you take an object, failing to take it won't trigger the ontake script; but if the player drops the object and subsequently takes it (or if an NPC drops some object before the player can take it), ontake runs regardless. This would likely be confusing and lead to hard-to-explain issues with more complex behaviour.

If you want to make ontake only run if the item is added to the inventory, it would make more sense to use if (HasScript (object, "ontake") and Contains (game.pov, object)) { - checking that the object is now in the inventory, which would be more consistent behaviour.


K.V.
03 Aug 2024, 11:37

Aha!

Good stuff!

Thanks, mrangel!