We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

How to call a JavaScript function from a separate .js-document?

Home Forums General Questions How to call a JavaScript function from a separate .js-document?

  • This topic has 3 replies, 2 voices, and was last updated 2 years ago by kdv.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #58997
    Tim
    Customer

    Hello there, :bye:

    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. :wacko:
    How can I implement this with Puzzles? I would be very happy about any help.

    #59000
    kdv
    Participant

    And how do you call DoSpecialStuff() in the puzzles? From the puzzle exec 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.

    #59016
    Tim
    Customer

    Hi kdv77kdv,

    thanks for your quick reply! :good:

    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.
    #59037
    kdv
    Participant

    the exec script puzzles won’t allow you to call DoSpecialStuff() function. It sees nothing outside except app, v3d, VARS and PROC variables. But you can call this functios from the external function myJSFunction. A long way to call ))) DoSpecialStuff() is not an external function and cannot be called by the call 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.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.