Sripting: Getting Started


#1

My apologies if there is already a getting started thread for scripting. I’ve created some custom entities, uploaded them to a server and instanced them in a domain. I deduced that the script link in the entity is a logical pointer to the script and suspect that placing a valid js function script on a remote server (like the fbx) should be then linked via script.

Thus far however my entities remain unresponsive. (I’m using scripts taken directly from the examples - bird tweet and sitonentity -

Is there a step by step or similar thread that i can use to verify my assumptions and search for the problem?


#2

To test with least possible problems, paste the entire script directly into the “script URL” path, and the entity should respond to the script, this makes sure the script is still good and the script engine is healthy.

If that works then double check the URL path you are using, and keep an eye on the console logs for errors.


#3

@Adrian Paste thge script into url path seems not to work anymore. at least the last time we wanted todo that with @thoys it failed.


#4

Tried the direct paste method with two scripts - one from the samples one from the script demo folder. Neither had any apparent impact. Is there a super simple ‘hello world script that i can use to verify that scripting is working in my instance?’


#5

scripts btw are here: http://p0qp0q.com/w3d_assets/chairSit.js and http://www.p0qp0q.com/w3d_assets/tweet.js


#6

The problem appears to be in clickDownOnEntity - scripts with clickDownOnEntity appear to not function in the latest builds of interface - while other scripts seem to work. Is this a known issue?


#7

There seems to be several issues at play here.
@Richardus.Raymaker
The direct injection system still works fine as at the latest build.

@Hiro
The script you are testing is called playSoundOnClick, yet the function used in the script is enterEntity, so it wont respond to a click, it will respond if you move into it.
Next these entity scripts dont like it when there are comments in the code, make sure you strip out any comments.

Please refer to this docs page for some examples.
http://docs.highfidelity.com/v1.0/docs/entity-script-examples

I have just tested this script

(function(){
    var clicked = false;
    this.clickDownOnEntity = function(entityID, mouseEvent) {
        if (clicked){
            Entities.editEntity(entityID, { color: { red: 0, green: 255, blue: 255} });
            clicked = false;
        }else{
            Entities.editEntity(entityID, { color: { red: 255, green: 255, blue: 0} });
            clicked = true;    
        }
    };
})

and it behaves as expected, changes color on click.


#8

Thanks Adrian,

I had actually changed that script to use the enterEntity to see if the event was the issue - but seeing your note I suspected that the problem with both scripts was the comments. I removed the comments - and after some struggles to reset / reload the scripts both seem to be working now.

While we’re on a roll. … where does the print command send the output? I don’t see it in the log, or in the console available from within interface. Is there an output console or debug utility that is accessible?

Allen


#9

CTRL/L brings up the console log

Click “Reveal log file” to bring up a local copy

print outputs there