ID:1796392
 
(See the best response by Lummox JR.)
Long story short: I'm trying to create an app to help people utilize iOS's native controls through DM/JavaScript. Also to add support for an on-screen gamepad.

In Objective-C I'm able to grab a JavaScript context and call functions on that context.

EX:

Javascript:

<html>
<head>
<title>Demo</title>
<script type="text/javascript">
function test(value) {
consoleLog("My debug message");
return value;
}
</script>
</head>
<body>
</body>
</html>



Objective-C:

self.jsContext = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
JSValue *value = [self.jsContext evaluateScript:@"test(4)"];


I can call and get the value from that javascript function in Objective-C. I also setup a consoleLog method that can be called in JavaScript to print out messages in Xcode's output log. I'm not JavaScript expert. My question is how do I properly get the BYOND game's context and what are some examples of calling functions on it? And how can I add custom functions to it where I can call them. My end goal is to create a BYOND client app that loads the game into a full screen web view that can call JavaScript methods to control the game. I want to get it to the point people can use a on-screen gamepad and/or native iOS functionality in their BYOND game through this app.

Any help would be appreciated, thanks!
Best response
The webclient docs explain the main object used to interact with the webclient on the JS level. It's simply "byond" (it's also a function), and since it's window-global it could be referenced as window.byond.

For instance, say you want to send a text message to the default output control.

byond(':output').output({text: "This is a message.\n"});


Or for a more complex example, say you wanted to use winget to grab the current state of a control.

var checked = (byond('mybutton').winget('isChecked') == "true");


You can call winget() or winset() with an object literal if you want to get more properties at once. For instance:

var/props = {isVisible: null, fontSize: null};
byond('alabel').winget(props);
props.isVisible = (props.isVisible == 'false'); // invert
byond('alabel').winset(props);


There are more complex things you can do obviously, but those are some of the basics.