tipforeveryone
Bronze Supporter
|
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).dominance(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.
|
|
07-26-2024 10:38 AM |
|
Esenthel
Administrator
|
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 |
|
tipforeveryone
Bronze Supporter
|
RE: Object parameters do not work if create dynamically ?
|
|
07-26-2024 07:03 PM |
|
Esenthel
Administrator
|
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 |
|