ID:1738444
 
(See the best response by Doohl.)
I've been playing around with the webclient while reading LummoxJR's webclient document, and while it is very detailed, it assumes a lot (I'm aware LummoxJR said it would be revised and improved later on).

Something I'm having an issue with is calling functions on both default and custom objects. Here is what I'm using to test things out:

<body>

<byondclass name = "coutput">

<script>

(function() {
return {
config: { isdefault: 1 },

fn: {
client_connected: function(obj, sub) {
this.elem.innerHTML = "client has logged in!";
//this.document.write("client has logged in!");
//this.document.write(obj.name + "client has logged in!");
}
}
};
})()

</script>

</byondclass>

<div id = "main_window" byondclass = "child" skinparams = "left: map; right: output; splitter: 50; is-vert = true">
<div id = "map" byondclass = "map" style = "size = 1024x608; zoom = 1"></div>
<div id = "output" byondclass = "coutput"></div>
</div>

</body>


And here is what I'm using to [attempt] to call my defined function, client_connected:

src << output(list2params(list(src)), "output:client_connected")


Nothing shows up in the output and there are no console errors. What's interesting is when I disable my environment's .dms file and run the game, I do get output that says "the + player" (which is the type of src), but that's not the output I'm looking for. More, I'd like to know what's happening that causes that message to appear.

Thanks.
Best response
Hmm! Here's what I would do:

I don't think user-defined functions in fn can be called in DM code. Instead, what I think you should be doing is relying on what you're given. For instance:

winset: function(props, sub) {

if(props.action == "connect") {
this.elem.innerHTML = props.client + " has connected!";
}
}


You'd then use winset to deliver commands to the "output" element.

winset(client, "output", "action=connect;client=[key]")
In response to Doohl
Thanks for the response.

I got something working thanks to you. I still have many questions though. For example, you placed your winset under fn, which works fine, but once it's moved under winsetfn, it seemingly stops working. That shouldn't be since the doc reads:

In winsetfn you have a list of functions that can handle winset or winget; these override any that are found in byond.winsetfn.

Some other things also don't seem to be working, like the is-default setting. I've been trying to get it to work with an output control using both the config member and the skinparams setting, but no success. I say this because I can get things to output to world.log just fine, but not to the output control.

I'm also wondering how I'm supposed to use the sub argument (or any additional argument for that matter), as I can only seem to use the first one. For instance, for output(obj, sub), the doc reads:

Output something to this control. obj is an argument that may contain one of several members:

So I actually got that proc working, but obj only ever used text; no matter how many different variations of the output proc I sent with different values, it only used text.

Nonetheless, I'm confused as far as how Byond is supposed to interface with this new webclient stuff. It's all good though, and I don't really expect you to have the answers, as it seems your team is one of the few, if not the only to really dive into all of this.

For now I'll go back to my original setup while continuing to mess around with the webclient, since that's all I can really do at this point.