These are chat archives for highfidelity/hifi

11th
Apr 2017
Don Hopkins
@SimHacker
Apr 11 2017 06:07
Hello fellow avatars ;) I'm developing a voting box and I need some help testing it out, please!
I put it up on my server:
It's an interface script you load into your running scripts, and it uses two entity scripts:
That creates a box with this entity script: http://donhopkins.com/home/hifi/VotingBoxEntity.js and a text with this entity script: http://donhopkins.com/home/hifi/VotingBoxTextEntity.js
I need another person to test it, because it behaves differently if the owner clicks on it, or somebody else does.
Rob Kayson
@MrRoboman
Apr 11 2017 06:11
I'll check it out. one sec.
Don Hopkins
@SimHacker
Apr 11 2017 06:11
I am new to this so I need help figuring out how to let you into my sandbox, or whatever it takes to test it.
It makes a box with a text label attached, that starts counting at "0".
When the owner clicks it, it resets to "0".
When somebody else clicks it, it increments the number and remembers them as a voter. You can only vote once. The first vote blinks green. Subsequent revotes blink red.
You can't take back your vote, until the owner resets it.
It blinks black when the owner resets it.
I've made it dynamic for now, since the spec didn't say how it should act, but I'm open to suggestion. When you grab it and throw it that counts as a vote!
That adds an interesting voter suppression dynamic, since you can vote for it once and then throw it far away so other people have more difficulty voting.
Basically it just counts how many times other people touch it.
Rob Kayson
@MrRoboman
Apr 11 2017 06:17
I created the box in Welcome. I don't see a text label.
If you click goto you should see the name of your sandbox and I can join you there if you like
Don Hopkins
@SimHacker
Apr 11 2017 06:20
Yes I see the oopsie! Just fixed it. Please try reloading that script. It should delete all your old voting boxes when you do that.
(It doesn't know how to save state yet so it has to blow them away when you reload)
Rob Kayson
@MrRoboman
Apr 11 2017 06:20
k
Don Hopkins
@SimHacker
Apr 11 2017 06:21
black-card-2568
Rob Kayson
@MrRoboman
Apr 11 2017 06:23
hmm. didn't destroy the other boxes. didn't notice any change when reloading the script
Ill come to black card
Don Hopkins
@SimHacker
Apr 11 2017 06:23
Might have crashed during trying to destroy, oops! But that's what it does when it's behaving.
Anything I need to do to give permission?
The fancy version will have a tablet interface, which will let you create a vote box with a label, show a live tally of all of your vote boxes, let you delete and reset them, etc.
That looks good, you voted once!
Click it again and see if it blinks red
Rob Kayson
@MrRoboman
Apr 11 2017 06:26
k
yep
did you see it too
I can't hear you at all.
I collide with them.
Don Hopkins
@SimHacker
Apr 11 2017 06:33
Sorry there is a loud fan here
Rob Kayson
@MrRoboman
Apr 11 2017 06:34
That's no problem. cant hear anything at all
Is that what you needed?
Don Hopkins
@SimHacker
Apr 11 2017 06:35
Ok so it's using MyAvatar.sessionUUID as the key to identify voters. So that should work across all time, not changing when you restart the client?
Yes thank you!
I could use some advice about debugging the javascript running in the tablet web browser, that's what I'm trying to do now.
Rob Kayson
@MrRoboman
Apr 11 2017 06:36
no problem.
Don Hopkins
@SimHacker
Apr 11 2017 06:36
I am working on a FancyVotingBox.js too, that has a web page, but it's not responding to clicks yet. Probably some silly syntax error. I'd like to see any console log or errors from that web browser!
Will the Qt debugging tools connect to it somehow?
Rob Kayson
@MrRoboman
Apr 11 2017 06:40
You're trying to debug js that running on a website or on an enitity?
Don Hopkins
@SimHacker
Apr 11 2017 06:40
Yes I'm hosting a .html page, like the Gemstone tutoral.
That's such an awesome powerful concept I just had to try it!
Rob Kayson
@MrRoboman
Apr 11 2017 06:41
can you right click in the browser and click inspect?
That should let you debug javascript
not familiar with gemstone tut
Don Hopkins
@SimHacker
Apr 11 2017 06:43
That is at:
Rob Kayson
@MrRoboman
Apr 11 2017 06:44
so youre creating a webpage entity in world?
Don Hopkins
@SimHacker
Apr 11 2017 06:44
I want it to send a "Ready" message to the client when it loads, and then the client will send it an update message with a list of all active voting boxes, and how many votes they have. Then it will show a list of those on the page, along with a text input that lets you enter a label and a button to create a new vote box with that label.
It will send an update message to the web page every time somebody votes for any of the outstanding vote boxes. Basically a little app to manage your ongoing votes.
I have registered tablet.webEventReceived.connect(onWebEventReceived);
Rob Kayson
@MrRoboman
Apr 11 2017 06:47
hmm. I'll have to look over the script.
Don Hopkins
@SimHacker
Apr 11 2017 06:47
But it's not getting called. So there's probably some syntax error or something stupid happening on the web page embedded in the tablet.
Is there a way to send a message the other way, from the interface to the web browser?
Then I can send update messages when the votes change!
Also I'd need to know when the web browser was closed, to stop sending update messages.
Rob Kayson
@MrRoboman
Apr 11 2017 06:48
Have you looked at the Script Log or the Log under Developer in the menu?
Don Hopkins
@SimHacker
Apr 11 2017 06:51
Yes, not getting any errors or even logs when I click the button.
Hey there was a syntax error in the html I just fixed, but now I find it must be getting cached.
I tested it by putting a "FOO" in the text, and bringing it up again, and there was no "FOO".
But I can put a random number in the url when you click the button!
Aha now I see my changes! Well that will help me debug it. ;) But is there a way to bring to bear the JavaScript debugging tools in Qt Creator, or some other remote debugging interface like that?
Oh I'm not creating a webpage entity in the world. I am making a tablet button, which calls tablet.gotoWebScreen to my html page, like the gemstone demo does.
So that web browser is running inside of the tablet, which isn't as far as I can tell represented in the world as an entity.
Don Hopkins
@SimHacker
Apr 11 2017 06:56
Or is it nested inside some object?
Don Hopkins
@SimHacker
Apr 11 2017 07:01
oh this looks useful: tablet.screenChanged.connect(onScreenChanged);
Then I can see when they closed my page.
Rob Kayson
@MrRoboman
Apr 11 2017 07:17
Hey, sorry got pulled away. How's the debugging? I'm about to sign out for the night.
Don Hopkins
@SimHacker
Apr 11 2017 07:35
I've got the js code on the page running and showing debugging messages by setting the text of a div. The bridge is loaded and I can send events without errors, but they don't show up.
I have just fixed my code to handle onScreenChanged, and it looks for when one with type Web and url = its URL (including the random number so it reloads)
So it's detecting when its page is opened and closed, and on those events it is connecting and disconnecting to the webEventReceived event of the tablet:
function onScreenChanged(type, url) {
    print("onScreenChanged", "type", type, "url", url, "lastWebPageURL", lastWebPageURL);

    if ((type === "Web") &&
        (url === lastWebPageURL)) {
        onVotingPage = true;
        tablet.webEventReceived.connect(onWebEventReceived);
        print("onScreenChanged connected onWebEventReceived");
    } else {
        onVotingPage = false;
        tablet.webEventReceived.disconnect(onWebEventReceived);
        print("onScreenChanged disconnected onWebEventReceived");
    }

}
The webEventReceived handler does this so far:
function onWebEventReceived(event) {
print("====== RECEIVED WEB EVENT: " + event);
    var eventData = JSON.parse(event);
    var eventType = eventData['type'];

    switch (eventType) {
        case 'Ready':
            // TODO: send message to web page with data to initialize interface.                                                                                          
            break;
        case 'CreateVotingBox':
            var title = eventData['title'];
            createFancyVotingBox(title);
            break;
        case 'ResetVotingBox':
            var votingBoxID = eventData['votingBoxID'];
            resetFancyVotingBox(title);
            break;
        default:
            print("onWebEventReceived unexpected eventType", eventType);
            break;
    }
}
But that is never getting called.

On the html side it's going:
function CreateVotingBox() {

            var title = $('#VotingBoxTitle').val();                                                                                                                       

            var clickEvent = {                                                                                                                                            
                type: "CreateVotingBox",                                                                                                                                  
                title: title                                                                                                                                              
            };                                                                                                                                                            

            var event = JSON.stringify(clickEvent);                                                                                                                       
            EventBridge.emitWebEvent(event);                                                                                                                              

ShowTest("CreateVotingBox event " + event);
}

So emitWebEvent is getting called ok, and ShowTest prints out the event json in the tablet html so I can see it, and it looks good.
Don Hopkins
@SimHacker
Apr 11 2017 11:57
There's a new version in http://donhopkins.com/home/hifi/FancyVotingBox.js
that is better, but after you reload the script it doesn't seem to get events from the web browser to the interface script any more. Still working on that, but restarting the interface makes it work again. Now it saves the state in the voting box userdata so it works across logout/login of the creator.
Rob Kayson
@MrRoboman
Apr 11 2017 17:12
Hey does anyone have a minute to test out a tetherball toy?
Run createTetherballStick.js - Tetherball Stick and Ball should appear in front of you.
Move hand to Tetherball Stick - Blue 'Equip' sphere should appear.
Pull trigger - Tetherball Stick should equip to the correct hand with a natural looking postion and rotation. The ball should fall away, but be caught by the newly created blue 'string'.
Move the Stick around, Fly fast, teleport - the ball should remain attached and act as if it's dangling from the stick.
Unequip by using the grip button - Stick should remain in current postion, Ball will return to the tip of the stick and the line will disappear.
Anthony Thibault
@hyperlogic
Apr 11 2017 17:42
@SimHacker Hey, I think we fixed the eventBridge reload issue in this PR. highfidelity/hifi#10118 which version of interface are you running?