Generated object error when trying to move children, etc.

I'm having difficulty. When POVs change their status as a magicuser, their flag changes, and there's a changed script which does a lot of the work setting attributes and making the spellbook pane POV specific.

In order to make it work so that game creators can change any POV they like into a magicuser, I told the script to create a spell storage room. But I'm having trouble then running certain scripts related to that room. I got this error

Error running script: Error evaluating expression '(GetDirectChildren((ProcessText(game.pov.name) + "spells")))': GetDirectChildren function expected object parameter but was passed 'playerspells'
magicuser on

I can move the spells to the room after it's created. But I can't seem to find them once moved and move them back to "spells_known" when the pov becomes a magic user again.

How do I tell the GetDirectChildren function Or other functions which don't behave like move object, that the string I'm passing is the name of the room?


What are you running ProcessText? All that does is check if the POV name contains any text processor commands. I don't think { is a valid character to include in an object name anyway.

I think what you want is: GetDirectChildren (GetObject (game.pov.name + "spells"))

GetObject is the function that takes an object's name and returns the actual object. But note that if this room doesn't exist, you'll still get an error. So make sure you include some kind of check to make sure this code isn't called before the spell room is created.

(My usual way of dealing with spells is to put them in the inventory, and make them invisible so that they don't show up in all the standard inventory stuff; or to keep them in a single location and give the POV object an objectlist attribute showing which ones they've got)


Mr. Angel! You really are amazing. I'm saving your idea to look at later about lists and the use of spells for the player. Learning a little here and there as I go.

Your solution for finding a way to let the system know I wanted the room with the name rather than sending it a string worked. Of course!

The context is using Pixie's CombatLib where he already had all player spells going into a room called "spells_known" and I added the 2nd inventory library so I could make an inventory pane for that room instead of merely pulling the list with a command and function.

But it wasn't set up for ChangePOV or for situations where the player might become a magicuser mid-game and/or lose their magic ability. So I created the "changedmagicuser" script to be added to any POV. Which reads a flag that gets set when the change happens. The full script looks like this:

if (GetBoolean(this, "magicuser")) {
  if (HasAttribute(this, "mana")) {
    if (HasAttribute(this, "mana_max")) {
    }
    else {
      this.mana_max = 0
    }
    dictionary add (game.pov.statusattributes, "mana", "MP: !")
  }
  else if (HasAttribute(this, "mana_max")) {
    if (HasAttribute(this, "mana")) {
    }
    else {
      game.pov.mana = 0
    }
    dictionary add (game.pov.statusattributes, "mana", "MP: !")
  }
  else {
    SetMana
    dictionary add (game.pov.statusattributes, "mana", "MP: !")
  }
  if (GetBoolean(game, ProcessText(game.pov.name) + "spells")) {
    msg ("Checking for spells")
    foreach (o, GetDirectChildren(GetObject(game.pov.name + "spells"))) {
      MoveObject (o, spells_known)
      msg ("moved a spell in!")
    }
    if (GetBoolean(game, ProcessText(game.pov.name) + "spells")) {
      msg ("Checking for spells")
      foreach (o, GetDirectChildren(GetObject(game.pov.name + "spells"))) {
        MoveObject (o, spells_known)
        msg ("moved a spell in!")
      }
    }
    else {
      create (ProcessText(game.pov.name) + "spells", "editor_room")
      foreach (o, GetDirectChildren(GetObject(game.pov.name + "spells"))) {
        MoveObject (o, spells_known)
      }
      msg ("Created playerspells for you and moved spells into spells known...")
      SetObjectFlagOn (game, ProcessText(game.pov.name) + "spells")
    }
  }
  else {
    create (ProcessText(game.pov.name) + "spells", "editor_room")
    foreach (o, GetDirectChildren(GetObject(game.pov.name + "spells"))) {
      MoveObject (o, spells_known)
    }
    msg ("Created playerspells for you and moved spells into spells known...")
    SetObjectFlagOn (game, ProcessText(game.pov.name) + "spells")
  }
  InitInv2 ("Spells")
  SetInv2 (spells_known)
}
else {
  this.mana = 0
  this.mana_max = 0
  dictionary remove (game.pov.statusattributes, "mana")
  if (GetBoolean(game, ProcessText(game.pov.name) + "spells")) {
    msg ("Checking for your spells")
    foreach (o, GetDirectChildren(spells_known)) {
      MoveObject (o, GetObject(game.pov.name + "spells"))
      msg ("moved a spell! out")
    }
  }
  else {
    create (ProcessText(game.pov.name) + "spells", "editor_room")
    foreach (o, (GetDirectChildren(spells_known))) {
      MoveObject (o, GetObject (game.pov.name + "spells"))
    }
    msg ("Created playerspells for you")
    SetObjectFlagOn (game, ProcessText(game.pov.name) + "spells")
  }
  InitInv2 ("")
  SetInv2 (emptyroom)
}
UpdateStatusAttributes
UpdateStatus

Now the idea will be to add the new spell inventory parts to the ChangePOV process so that the game also correctly recognizes when you change your POV from a magic user to a non-magic user!

Thanks as always for all your help Mr. Angel. You, Pixie, and a couple others are going to get lines (or paragraphs) of recognition when I finally get something done that's worth sharing!


Log in to post a reply.

Support

Forums