About Store Forum Documentation Contact



Post Reply 
Object parameters do not work if create dynamically ?
Author Message
tipforeveryone Offline
Bronze Supporter

Post: #1
Object parameters do not work if create dynamically ?
I have realize something very basic but I did not notice from the beginning, I just want to confirm here
object parameters which are defined in 'Object Class' element only work when placing that object in editor manually ?
it does not work if I spawn object dynamically (Using Game.World.objCreateNear();

Code:
virtual void create(Object &obj)
{
    super.create(obj);
    
    Set_Param(obj, "collision", collision);
    Set_Param(obj, "gravity", gravity);

actor.collision(collision).gravity(gravity).ray(false).group(AG_PROP_DEBRIS).dom​inance(AG_PROP_DEBRIS);
}

void Set_Param(Object &obj, Str paramName, bool &assignedVariable){
   if(Param *par = obj.findParam(paramName)) assignedVariable = par.asBool();
}

here is my custom create function
I changed value in object editor, it is ok when I place object itself into the world in editor
but if I use Game.World.objCreateNear() those parameters are not applied.
(This post was last modified: 07-26-2024 10:43 AM by tipforeveryone.)
07-26-2024 10:38 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Object parameters do not work if create dynamically ?
I recommend that you run in debug mode, and check what's the problem.
It should work I think.
07-26-2024 03:32 PM
Find all posts by this user Quote this message in a reply
tipforeveryone Offline
Bronze Supporter

Post: #3
RE: Object parameters do not work if create dynamically ?
I dont think it because of my code, here, take a look.
I put a breakpoint after Set_Param() function, that lifeTime value is zero, not 500 as my setting in object editor.

https://i.gyazo.com/bb4fb35bf68b5be95870...95ebac.png
https://i.gyazo.com/9951dc73f9734b91342a...2b4ac1.png

edit: this problem is found by another on discord channel too. I ask in "help" section before put the problem here
(This post was last modified: 07-26-2024 07:05 PM by tipforeveryone.)
07-26-2024 07:03 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Object parameters do not work if create dynamically ?
I've modified tutorial but it works fine:

!! Make sure you call Object.sortParams after adding new parameters. !!

Code:
/******************************************************************************/
bool check;
class Test : Game.Item
{
   virtual void create(Object &obj) // create from object
   {
      super.create(obj);
      if(check)
      {
         C Param *p=obj.findParam("test");
         Exit(p ? p.value.s : S+"not found");
      }
   }
}
Game.ObjMap<Test> Items;

File SaveGame; // file used to store world state
/******************************************************************************/
void InitPre()
{
   INIT();
   Ms.hide();
   Ms.clip(null, 1);

   Cam.dist =10;
   Cam.yaw  =-PI_4;
   Cam.pitch=-0.5;
   Cam.at.set(16, 0, 16);
}
/******************************************************************************/
bool Init()
{
   Physics.create();

   Game.World.activeRange(D.viewRange())
             .setObjType(Items, OBJ_ITEM)
             .New(UID(3829896559, 1088474000, 4168763052, 388400472));
   if(Game.World.settings().environment)Game.World.settings().environment->set();

   return true;
}
/******************************************************************************/
void Shut()
{
   Game.World.del();
}
/******************************************************************************/
bool Update()
{
   if(Kb.bp(KB_ESC))return false;
   Cam.transformByMouse(0.1, 100, CAMH_ZOOM|(Ms.b(1)?CAMH_MOVE:CAMH_ROT));

   if(Kb.bp(KB_F2))                  Game.World.save(SaveGame.writeMem());  // save game to file in memory
   if(Kb.bp(KB_F3)){SaveGame.pos(0); Game.World.load(SaveGame           );} // reset file position and load game from it

   Game.World.update(Cam.at);

   if(Kb.bp(KB_SPACE)) // on space
   {
      check=true;
      Object temp;
      temp.base(UID(1134879343, 1157937325, 4232119955, 3140023117)); // get barrel object parameters
      Param &p=temp.params.New();
      p.name="test";
      p.type=PARAM_STR;
      p.value.s="value";
      temp.sortParams();
      Game.World.objCreate(temp, Matrix(temp.scale3(), Vec(16, 4, 16))); // create new object at (16, 4, 16) position and give objects default scaling
   }
   return true;
}
/******************************************************************************/
void Render()
{
   Game.World.draw();
}
void Draw()
{
   Renderer(Render);
   D.text(0, 0.9, "Press Space to add a Barrel");
}
/******************************************************************************/
07-27-2024 12:24 PM
Find all posts by this user Quote this message in a reply
Post Reply