About Store Forum Documentation Contact



Post Reply 
References not valid after linking
Author Message
Fyttyn Offline
Member

Post: #1
References not valid after linking
I can't figure out why the references aren't valid after linking. Some more info... So I'm saving the game on shut. And checking if there's a save on init, and if so, load. The issue is when I load the worn items, it seems they aren't valid any more. My character isn't wearing his equipment any more, even though they're in his inventory still. On the first run, there are 6 worn elements (left/right pauldron, maul, dagger, daggercase, clothes), all valid and drawn. After exiting and running again, it loads, and then there are 6 worn elements, but none are valid or drawn. What am I doing wrong?
Code:
Inside my Character class:
Memx<Reference<Item>> worn;
virtual uint drawPrepare()
   {
      FREPA(worn)
      {
         if(worn[i].valid()) {
            FREPAD(j, worn[i]->wearMeshes)
            {
               worn[i]->wearMeshes[j].mesh->draw(skel);
            }
         }
      }
      return super.drawPrepare();
   }
   virtual void drawShadow()
   {
      FREPA(worn)
      {
         if(worn[i].valid()) {
            FREPAD(j, worn[i]->wearMeshes)
            {
               worn[i]->wearMeshes[j].mesh->drawShadow(skel);
            }
         }
      }
      super.drawShadow();
   }
// io
   virtual bool save(File &f)
   {
      if(super.save(f))
      {
         inv.save(f);
         worn.save(f);
         health.save(f);
         f<<speed<<reach;
         return f.ok();
      }
      return false;
   }
   virtual bool load(File &f)
   {
      if(super.load(f))
      {
         inv.load(f);
         worn.load(f);
         health.load(f);
         f>>speed>>reach;
         return f.ok();
      }
      return false;
   }
   virtual void linkReferences()
   {
      super.linkReferences();
      FREPA(worn)
      {
         worn[i].link(Game.World);
      }
   }
01-28-2020 04:23 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: References not valid after linking
worn[i].link(Game.World);
Will only link references with global objects in the world.
It does not search for sub objects (such as items in the inventory of a character)
So you can try to manually find/link those objects in the inventory.
01-28-2020 04:44 AM
Find all posts by this user Quote this message in a reply
Fyttyn Offline
Member

Post: #3
RE: References not valid after linking
(01-28-2020 04:44 AM)Esenthel Wrote:  snip

wow that was quick. Thanks for the fast response!
01-28-2020 04:49 AM
Find all posts by this user Quote this message in a reply
Post Reply