Scripted Text Entity via javascript


#1

What if I wanted to script a text entity so that its content can come from something else than the userdata?

I’ve seen some photos depitcing chats written on an avatar personal board, but was not able to find out it and thus I’m clueless on which APIs and functions need to be called to achieve this result.

BTW: what happened to sign post chat script? I was not able to find it anymore in the marketplace or anywhere.


#2

This is the documentation on how to “script” text entities. I’m completely confused on how to script them from this documentation :slight_smile: I would really love to be helped in implementing the last sentence of this…

In the API documentation I’ve found the following interesting snippet:

var text = Entities.addEntity({
type: “Text”,
position: Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: -5 })),
dimensions: { x: 0.6, y: 0.3, z: 0.01 },
lineHeight: 0.12,
text: “Hello\nthere!”,
faceCamera: true,
lifetime: 300 // Delete after 5 minutes.
});

Now how can I adapt a script attached to a TextEntity to modify “current” entity? Is there a current entity that I can use to modify?


#3

Regarding the sign chat,

Something broke it a while back, regarding positioning and its scaling, and it hasnt been back since as the cause hasn’t been fixed and I haven’t had the time to look into it due to my RL Work and the Blender Plugin taking my time.

In anycase, You can simply use Entities.editEntity to edit the entity again to change it.


var textId = Entities.addEntity({
type: "Text",
position: Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: -5 })),
dimensions: { x: 0.6, y: 0.3, z: 0.01 },
lineHeight: 0.12,
text: "Hello\nthere!",
faceCamera: true,
lifetime: 300
});

// Later
Entities.editEntity(textId, {text: "this is new text"});

You just have to make sure the id is consistant and points to the entity.

So Forexample with an Entity script that you can add to a new text entity.

(function () {
    return {
        id: undefined,
        preload: function (entityId) {
            this.id = entityId; // Can Be stored in memory, referred inside script loops, etc.
        },
        mousePressOnEntity: function (entityId, value) {
            // or just use the id provided in the interaction call
            console.log(JSON.stringify(value));
            Entities.editEntity(entityId, {
                lineHeight: 0.0320,
                text: this.id + "\n" + value.type + "\n" + value.button
            });
        }
    };
});

With the sign script, the entity Id is contained in memory of the script, and on menu button click it gets erased / recreated.


#4

Thanks @Menithal very useful, will try as soon as I can access HF.
Regarding your script, I’ve found an old reference of its address and tried it and it seemed working.
It is really useful and I noticed that you worked a lot to make it appear with the correct joint angle for the arms of the avatar.