How do I access function in my javascript

0 favourites
  • 8 posts
  • Hello there!

    Can someone explain how i could send a variable to a function in my JavaScript, i have added to my Project? There are some calculations i would have to do within this function and then return a string to construct3 again to set it to an variable in my game.

    Can someone tell me how to do that?

    Thank you very much!

    example:

    I have the score and a string (a scecret), i want to send to my crypto.js script. (there is a function inside, which should encrypt those values). Then the function should return a value i would have to return in construct3 and save it, to post this to an url.

    Values in Construct: Score (int), Secret(string).

    Send values to JavaScript: ExecuteJavascirpt(Crypto.js(Score, Secret))

    JavaScript return values to construct: String(XXXX.YYYYY.ZZZZZ) ---- (This function generates a huge string (webtoken), with the encoded values, i would Need in construct to send it to an url)

    Please tell me, if there is something unclear

    In Construct3:

    global variable WebToken:string;

    Set WebToken to (Browser.ExecJS("crypt("&highScore&","&secretVar&");"))

    JavaScript Called Crypto.js, saved in Files folder:

    <script>

    function crypt(score, string){

    var header = {

    "alg": "HS256",

    "typ": "JWT"

    };

    var stringifiedHeader = JSON.stringify(data);

    var encodedHeader = btoa(stringifiedHeader)

    return encodedHeader ; (or even a test retrun "string" doesnt work)

    </script>

    }

    I want to get the generated string from the JavaScript (encryptedString) to set the webtoken varialbe to this value. It does not return anything... is there something wrong? How could i check if the JavaScript function will be triggered?

    __________________________________________________________

    Update:

    Found this: but why is this not working in my case?

  • Any Help would be awesome and very important for me..

    Em i right if i include a javascript file into my folder called "files" and in this script is a function like i described above, it should be possible to call the function with some parameters and return a value from it - with the browser.execute("myfunction();") method? Otherwise i dont get it, how to run some JavaScript Code...you can generate a JavaScript file in the files direction, but you cant Access it?

    Set WebToken variable:

    Browser.ExecJS("(function(){ var header = {'alg':'HS256','typ':'JWT'};

    var stringifiedHeader = JSON.stringify(header);

    var encodedHeader = btoa(stringifiedHeader); altert(encodedHeader); })")

    Doesnt work either.

    I checked 100 of differend posts but i dont know why there is no tutorial or example or something, that can provide a guy who never did this before.

    Thanks again for any help!

    I also loaded the JSShell plugin from Rex, but there is no documentation available, with some examples or something. The construct3 files cant be downloaded, because the link isnt actual.

  • Here is a demo I made using R0j0hound's example from some other post:

    https://www.dropbox.com/s/odcvl711o1b8i ... .capx?dl=0

  • dop2000

    Thank you very much! With your help i can now understand how it can be done! Very nice!

    Now i have another question, depending on the encryption. The secret encryption needs the HMACSHA256() algorithm, this is part of a library, and not only javascript native programming.

    Is there a possability to include a library into construct3 - For example Crypto.js, it contains hmac encoding functions? Or do you know what would be the best way to achieve hmacsha256 encoding?

    Again thank you so much for your answer! Youre the best!

  • Javascript librarys with the embeded codec cant be read - i guess - or doesnt seems wo work. We tried to include a cryptojs library with needed functions, but it doesnt work.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It works! You have to make a reference in the index.html file, after that you can reference to every javascript file and get those functions to work.... aweseome....

    It was difficould to understand the communication between construct3 and JavaScripts - but after you get it once it is awesome to access your own code.

    Kind of love this engine and Ashley `s perfect support.

  • Phacanu

    Nice! Thank you for your link!

    I havent tried it out right now but the first look is very promising! Ill try it out when i have less stess Because currently it works with the help of dop2000 feedback.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)