Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

I updated sugarcube now my javascript isn't working

I have external javascript files that I uploaded using macro below. Since updating sugarcube none of them are working and I'm panicking!

<<silently>>
<script>
macros =
{
handler: function(place, object, parameters)
{
var se = document.createElement("script");
se.type = 'text/javascript';
se.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js";
var hT = document.getElementsByTagName("HEAD")[0];
hT.appendChild(se);
if(se.innerText) {eval(se.innerText);}
else {eval(se.textContent);}
}
}
</script>
<script type="text/javascript" src="lib/sweet-alert.min.js"></script>
<link rel="stylesheet" type="text/css" href="./lib/sweet-alert.css"/>
<script type="text/javascript" src="onclick.js"></script>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '895302790553250',
xfbml : true,
version : 'v2.4'
});
};

(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<<endsilently>>

Comments

  • Don't panic! (thank you, Mr. Adams)

    In the future, when posting code, please use the code tag.


    What story format, and version, were you using before? When you say you "updated" SugarCube, updated it to what version? Also, where you placing this code at?


    A note about your shown code as I await your answers to the above. Your sole "macro" isn't. Jamming a method named handler directly onto the legacy macros object does not a macro make. You are, at the very least, missing the macro body itself. In other words, your "macro", as shown here, is, and has always been, completely non-functional.

    It's also a moot point, however, since your non-functional "macro" is attempting to load jQuery, which is something that SugarCube already includes, thus rendering your broken "macro" pointless in the first place.

  • Also, which browser are you using? Chrome or Opera?
  • You know what, never mind. Here's an updated version of your code which bypasses several problems with the old stuff. In particular:
    • jQuery is not loaded, since your broken "macro" wasn't loading it anyway and SugarCube already makes it available to you.
    • sweetAlert is now pulled from a CDN, since some browsers (e.g. Chrome) now refuse to load local scripts as a security measure and you were already doing network requests for Facebook's SDK.
    • Facebook's SDK is now specifically pulled via HTTPS, since that's the only way they serve it. Also, using a protocol-relative URL here will break if the project is loaded locally, since the relative protocol will be file: (which obviously won't work).
    Throw your old code in the bit bucket and burn it with fire (additionally, you should no longer need your local sweetAlert files, so they may also be discarded). Afterward, put the following in a script tagged passage and profit (for realsies):
    (function ($) {
    
    	/*
    		Setup the `fbAsyncInit` function.
    	*/
    	window.fbAsyncInit = function() {
    		FB.init({
    			appId   : '895302790553250',
    			xfbml   : true,
    			version : 'v2.4'
    		});
    	};
    
    	/*
    		Load the external scripts and stylesheets.
    	*/
    	$(document.head)
    		.append('<link id="sweetalert-stylesheet" rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/t4t5/sweetalert/master/dist/sweetalert.css">')
    		.append('<script id="sweetalert-script" type="text/javascript" src="https://cdn.rawgit.com/t4t5/sweetalert/master/dist/sweetalert.min.js"></script>')
    		.append('<script id="facebook-jssdk" type="text/javascript" src="https://connect.facebook.net/en_US/sdk.js"></script>');
    
    })(jQuery);
    
  • Thanks so much for leaving such an extensive reply. I updated sugarcube to bypass the chrome issues and I think in doing so I messed up the most recently saved version of the game because an older version still works.

    Also, thanks for the update on the code, it's well and truly thrown in the bin. Sorry about not using the code tag, clearly my first time on the forums. I'll remember next time, thanks for much for your help!
  • Also, I wasn't initially using sugarcube which is why I had attempted to write a macro for jQuery. I switched later on when I realised that all the things I wanted to include in the story were already written into sugarcube. I didn't realise that it uploaded jQuery so I think I'll head back to the documentation to make sure there is nothing else I missed that could be making my life easier.
Sign In or Register to comment.