Home › Forums › General Questions › How to call a JavaScript function from a separate .js-document?
Tagged: call external function, call function, external script, javascript, js, puzzles
- This topic has 3 replies, 2 voices, and was last updated 1 year, 10 months ago by kdv.
-
AuthorPosts
-
2022-12-12 at 10:38 pm #58997TimCustomer
Hello there,
I am quite inexperienced with JavaScript in Verge 3D, but have managed to create a custom JS function in the “appname”.js file and call it when needed with Puzzles. But I am struggling with calling a function from another .js-file.
I would like to call a function in separate .js, because I want to be able to expand the file as clearly as possible later.
Inside my Verge project folder there is a subfolder called “js” and in there is my “special.js” file. special.js only contains:
“function DoSpecialStuff() {
// add your code here, e.g. console.log(‘Hello, World!’);
console.log(‘Just added some JavaScript!’);
}”In the index.html, I register the “special.js” via ”
<script src=”js/special.js” type=”text/javascript”></script>”
right before “</body>”I read the whole documentation about this, but can’t get it to call “DoSpecialStuff” unfortunately.
How can I implement this with Puzzles? I would be very happy about any help.2022-12-13 at 2:21 am #59000kdvParticipantAnd how do you call
DoSpecialStuff()
in the puzzles? From the puzzleexec script
I suppose?Puzzles and JS coding. Fast and expensive.
If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of the meaning at all.
2022-12-13 at 10:53 am #59016TimCustomerHi kdv77kdv,
thanks for your quick reply!
I have tried to call it by using the Puzzle “call external function”.
Before I do that I try to register the document in an “exec script”-Puzzle to make it accessible.
I suppose the problem might be just there, because my DoSpecialStuff function is still marked red in Puzzles. As far as I know, this means that the function was not found and therefore can not be accessed.I have prepared an overview of how I set things up and commented it out in the image to keep things tidy. Please find it attached.
Attachments:
You must be logged in to view attached files.2022-12-13 at 6:32 pm #59037kdvParticipantthe
exec script
puzzles won’t allow you to callDoSpecialStuff()
function. It sees nothing outside exceptapp
,v3d
,VARS
andPROC
variables. But you can call this functios from the external functionmyJSFunction
. A long way to call )))DoSpecialStuff()
is not an external function and cannot be called by thecall eternal function
puzzle. It’s just a function in another script file.Puzzles and JS coding. Fast and expensive.
If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of the meaning at all.
-
AuthorPosts
- You must be logged in to reply to this topic.