// spil API for GM:Studio // commands: // get_brandimage(); // get_brandlink(); // checkpaused(); // request_ad(); document.getElementsByTagName('head')[0].innerHTML += ''; function loadScript(url, callback) { // Adding the script tag to the head as suggested before var head = document.getElementsByTagName('head')[0]; var script = document.createElement('script'); script.type = 'text/javascript'; script.src = url; // Then bind the event to the callback function. // There are several events for cross browser compatibility. script.onreadystatechange = callback; script.onload = callback; // Fire the loading head.appendChild(script); } var brandimage = ""; var brandlink = ""; var apiloaded = false; var spil_loaded= function() { apiloaded = true; GameAPI.loadAPI(function(API) { brand = API.Branding.getLogo(); }); }; // The function in the second argument runs AFTER the script in the first argument finishes loading loadScript("http://cdn.gameplayer.io/api/js/game.js", spil_loaded); // returns a comma-separated string, first value is an image link, second is the url to be opened when image is clicked function get_brand() { if(apiloaded == false) { return ""; // api not yet loaded } brandimage = brand['image']; brandlink = brand['link']; brand = brandimage + "," + brandlink; return brand; } // returns a comma-separated string, contains key names you can use to retrieve the available button options. function button_listlinks() { if(apiloaded == false){ return ""; // api not yet loaded } links = GameAPI.Branding.listLinks(); //alert(links); links = links.join(); return links; } // linknames can be acquired by calling this function: spilAPI.Branding.listLinks(); // the most common one to use is 'more_games' function button_getlink(linkname) { if(apiloaded == false){ return ""; // api not yet loaded } button = GameAPI.Branding.getLink(linkname); buttonimage = button['image']; buttonlink = button['url']; button = buttonimage + "," + buttonlink; return button; } // after calling this function, GM should keep calling checkpaused() in case an ad does pop up function request_ad() { if(apiloaded == false){ return 0; // api not yet loaded } GameAPI.GameBreak.request(ad_loaded, ad_done); //alert("now requesting an ad!"); return 1; }; // callbacks to pause or load the game var ad_loaded= function() { pausegame = 1; //alert('ad loaded! pause the game'); } var ad_done= function() { pausegame = 0; //alert('ad done! unpause the game'); } // GM will keep calling this function when the game is expecting to be paused or unpaused at any moment function checkpaused() { return pausegame; }