Functions to Deal with Clones

Hello!

Please add functions or suggest changes!

Thank you!


Revised functions:

  <function name="GetDirectCloneChildren" parameters="parent, prototype" type="objectlist">
    return (FilterByAttribute(GetDirectChildren(parent),"prototype", prototype))
  </function>
  <function name="IsCloneOf" parameters="object, prototype" type="boolean">
    return (object.prototype = prototype)
  </function>
  <function name="ScopeReachableClonesOf" parameters="prototype" type="objectlist">
    return (FilterByAttribute(ScopeReachable(), "prototype", prototype))
  </function>
  <function name="GetRandomReachableCloneOf" parameters="prototype" type="object">
    PickOneObject (ScopeReachableClonesOf(prototype))
  </function>
  <function name="AnyReachableCloneGetBoolean" parameters="prototype, attribute" type="boolean">
    return (ListCount(FilterByAttribute(ScopeReachableClonesOf(prototype), attribute, true))>0)
  </function>
  <!-- This function written by mrangel -->
  <function name="GetReachableClonesWithBoolean" parameters="prototype, attribute" type="objectlist">
    return (FilterByAttribute(ScopeReachableClonesOf(prototype), attribute, true))
  </function>

In ReachableClonesGetBoolean, you're testing if one or more clones has that flag. In that case, once you found it there's no need to loop over the remaining clones (and there's actually no need to loop over all the reachable objects to find out if one is a clone. In this case, you can make it faster by:

  <function name="ReachableClonesGetBoolean" parameters="prototype, attribute" type="boolean">
    foreach (o, ScopeReachable()) {
      if (HasObject(o, "prototype")) {
        if (GetBoolean(o,attribute)) {
          if (o.prototype = prototype) {
            return (true)
          }
        }
      }
    }
    return (false)
  </function>

However, I'm not sure what you'd use this function for. Every case I can think of, it would be more useful to return a list of clones with that attribute; or the number of them. In which case you can't stop as soon as you find one, so you'd do:

  <function name="GetReachableClonesWithBoolean" parameters="prototype, attribute" type="objectlist">
    return (FilterByAttribute(ScopeReachableClones(), attribute, true))
  </function>

Aha!

Good stuff!


ReachableClonesGetBoolean()
I changed it to return the first time it finds a clone with the attribute set to true.

This is to quickly check if the player has access to something like a cloned lantern which is currently switched on.


I've got ScopeReachableClones() to return the object list.


NOTE: ReachableClonesGetBoolean() has recently been changed to AnyReachableCloneGetBoolean().


The purpose of ReachableClonesGetBoolean()?

We have a friend who is a text-processor abuser.

This anonymous person is also very much into cloning.

There is so much code written at this point, going back and doing away any text-processor stuff is out of the question.

...but we can replace bits and pieces to make things work.

E.g.,

Say there is a lamp object in an out of world room. It's sole purpose is to be cloned.

Now, at some point during play, we want to know if a clone of lamp which is reachable is switched on.

There are many ways to approach this, I know, but the code consists of text-processor stuff nested inside each other numerous times and strung together more intricately than ... well, than I've ever seen! And it all works, except for a few bits concerning clones.

So, where there is something like:

{either lamp.switchedon:but at least you've got the lamp providing light.|and it's too bad you haven't switched that lamp on!}

...we could put:

{either "+ReachableClonesGetBoolean(lamp,"switchedon")+":but at least you've got the lamp providing light.|and it's too bad you haven't switched that lamp on!}

Hmm ... very specific case there. I can come up with a few more edge cases where that function could be useful. But they all seem to be tied in with hysterical raisins.


This looks like some very useful stuff, Im notorious for using clones(Generating npcs/monsters and so on) having functions to help work with em can only help


mrangel said: "...hysterical raisins..."

Very punny!

Talon said: "This looks like some very useful stuff, I'm notorious for using clones..."

Rock and roll!

Feel free to share any code you may have cooked up (or request a function we're overlooking)!


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

Support

Forums