[Scripting] How to read with javascript entity parameters?


#1

The little bit of own javascrpt code i made in the past, i know how to set entity parameters. But how do you read parameters, like position , rotation etc ?


#2

See http://jsref.docs.highfidelity.com/docs/getentityproperties


#3

That example is creating entity first.
In my setup i have the script inside the entity. so i do not know how to know the ID.
It looks like there’s no GetEntityID ?

Yes, i forgot most of the hify javascript things :frowning:

Uhmm… :flushed: It looks like this can work.

    print(EntityItemId);

Hmm, nope. doc page gives the idea that you get the id. but i get error.
[05/09 20:14:50] [WARNING] [UncaughtException] ReferenceError: Can’t find variable: EntityItemId in Entities 4:19

Getting a few flashbacks, this where already drama in the past. and back to square 0.
Now errror free, but no results

[05/09 20:25:48] [DEBUG] script:print()<< [object Object]

(function()
{ 
    
    this.clickDownOnEntity = function(entityID, mouseEvent) 
    { 
        var Ent = this.entityID;
        var copyEnt = Entities.getEntityProperties(Ent);
        print(copyEnt);
    }; 
    
}
)

#4

Instead of print(copyEnt) use print(JSON.stringify(copyEnt))
This will output details of the copyEnt object.


#5

Thanks, i kn ew it where something simple. But…
Does this still work correct withs cript that is running inside entity cube as example. The script is for now running from local disk.

The problem is that i do not get any output. This possible a user error and not a bug.

[05/09 22:10:52] [DEBUG] script:print()<< {}

(function()
{  
    this.clickDownOnEntity = function(entityID, mouseEvent) 
    { 
        var Ent = this.entityID;
        var copyEnt = Entities.getEntityProperties(Ent);
        print(JSON.stringify(copyEnt));
    }; 
}
)

#6

@Richardus.Raymaker Instead of …

var Ent = this.entityID;

… try …

var Ent = entityID;

I.e., without that “this”: then you’ll be using the “entityID” value that’s passed into the function when it is called, rather than “this.entityID” which refers to a property of the function object, which is very probably undefined and hence why you got nothing between the { } brackets printed.


#7

Goint to test that, i tried it before your fixes. Forgot to test it after.
And, i really hate the this stuff. I still don’t get that complete.

Again thanks.

ADD: That works. now we can puzzle further. Now i start to understand it again.