realXtend / tundra

realXtend Tundra SDK, a 3D virtual world application platform.
www.realxtend.org
Apache License 2.0
84 stars 70 forks source link

EC_DynamicComponent::SetAttribute doesn't work for EntityReference, AssetReference and AssetReferenceList #748

Open tapanij opened 10 years ago

tapanij commented 10 years ago

Trying to set EntityReference by code but it doesn't do anything.

Example:

// empty entityReference
var attrs = parentEntity.dynamiccomponent;
var racketRef = attrs.GetAttribute("racketRef");

// set entityReference
racketRef.ref = children[1];
console.LogInfo("racketRef:");
console.LogInfo(racketRef);
console.LogInfo("racketRef.ref:");
console.LogInfo(racketRef.ref);
// works fine so far but then:
attrs.SetAttribute("racketRef", racketRef);

racketRef = attrs.GetAttribute("racketRef");
console.LogInfo("2 racketRef:");
console.LogInfo(racketRef);
console.LogInfo("2 racketRef.ref:");
console.LogInfo(racketRef.ref); <-- didn't actually set the ref

Console log: ents: racketRef: [object Object] racketRef.ref: Entity "racket" (ID: 16) 2 racketRef: [object Object] 2 racketRef.ref: <-- empty ref. should be "Entity "racket" (ID: 16)

Stinkfist0 commented 10 years ago

Updated title: noticed that also AssetReference and AssetReferenceList values are not set properly.

Stinkfist0 commented 10 years ago

Note to self: make jsmodules\Tests\Api\Scene\DynamicComponent.js to test creation, writing and reading of each supported attribute type.

jonnenauha commented 10 years ago

Are you using Rocket or rex core/release? This would be helpful to know.

tapanij commented 10 years ago

Not 100% sure if I used linux tundra or rocket. Probably linux

jonnenauha commented 10 years ago

I've worked on this issue now and I think everything should be now resolved and a wider range of script setters not only for EC_DynamicComponent::SetAttribute but for normal attributes as well (eg. mesh.meshRef and placeable.parentRef).

Here is a quick rundown what you can do now (These will also for work with EC_DynamicComponent::SetAttribute):

mesh.meshRef = "test.mesh";
mesh.meshRef = { ref : "test.mesh", type : "OptionalType" };
mesh.meshRef = new AssetReference("test.mesh", "OptionalType");

mesh.materialRefs = [ "test1.material", "test2.material" ];
mesh.materialRefs = [ "test1.material", 
    { ref : "test2.material", type : "OptionalType" },
    new AssetReference("test3.material", "OptionalType") 
];
mesh.materialRefs = new AssetReferenceList("test1.material", 
    { ref : "test2.material", "OptionalType" }, 
    new AssetReference("test3.material", "OptionalType")
);

placeable.parentRef = "EntityName";
placeable.parentRef = 150;
placeable.parentRef = { ref : "EntityName" };
placeable.parentRef = { ref : 150 };
placeable.parentRef = new EntityReference("EntityName");
placeable.parentRef = new EntityReference(150);

var otherEnt = scene.EntityByName("EntityName");
placeable.parentRef = otherEnt;
placeable.parentRef = new EntityReference(otherEnt);
placeable.parentRef = null; // Clears ref
placeable.parentRef = undefined; // Clears ref

Let me know if there is a combo missing that you might want to be using or there are bugs in these ones. The DynamicComponent.js has now tests for all these cases and can be ran via --jsplugin jsmodules/Tests/Api/Scene/DynamicComponent.js once merged to core.

Stinkfist0 commented 10 years ago

Great!