Working with JS

Silver
Just looking at some JS code and I have absolutely no idea where to put it! I see under advanced that there's an option to put JS there, but that then wants you to save the file somewhere which doesn't appear right as the function to call it doesn't ask for a file extension. Hope I'm making sense.

OurJud
As far as I'm aware, you add it to the option under 'add script' (add javascript)

Silver
Specifically I'm looking at how Alex implemented his fading intro image. He says you call the JS function with:

JS.introScreen (GetFileURL("intro.jpg"))


I can probably get that bit right. But where do I stick the rest of it?

function introScreen(url) {
$("#gameBorder").hide();
$("<div/>", {
id: "introScreen"
}).css({
position: "fixed",
top: 0,
left: 0,
width: "100%",
height: "100%",
overflow: "hidden",
"text-align": "center",
display: "none",
}).appendTo("body")
.html("<img id=\"introScreenImg\" style=\"max-width:100%;max-height:100%;\" src=\"" + url + "\"/>");
$("#introScreenImg").load(function() {
$("#introScreen").fadeIn(4000);
setTimeout(function() {
finishIntroScreen();
}, 7500);
});
}

function finishIntroScreen() {
$("#gameBorder").show();
$("#introScreen").fadeOut(7000, function() {
$("#introScreen").remove();
});
}


I've tried putting it under Javascript in Advanced and I just ended up getting errors. Plus I don't know what file name to give it. Once I've got it working I'll be able to start tinkering with it.

OurJud
That would go in your main code, wouldn't it? Not sure where, though.

Try adding the call under 'turn scripts' (somewhere near the top of the left tree) >> add new script >> run javascript

And then the rest would go in your main code. Not sure what you mean about saving it. It would just be saved as part of your game.

jaynabonne
Put the JavaScript code in a file with a .js extension. Copy that file into your game folder (the folder where your game is). Then go into the Javascript section in Quest and select it from the drop-down list. (It will appear there after you copy it.)

Silver
And this:

JS.introScreen (GetFileURL("intro.jpg"))


Just gets slapped into code view when I want the above to happen? Because it's doing diddly squat. :D

jaynabonne
One thing that might help is for you to do this:
1) Run your game in desktop Quest
2) While it's running, after when the JS should have kicked in, hit F9. This will bring up the HTML Tools window.
3) Click on "Console" and see if there are any error messages.

Silver
Cheers. I'll give it a whirl tomorrow.

Silver
I've got it working in a test game. So just need to work out what I'm doing differently. :?

Silver
Got it working. Turns out I'd named the file intro.jpg instead of it just being a jpeg called intro. :roll:

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums