(Glowscript) Turning asynchronous jQuery function into synchronous function

37 views
Skip to first unread message

KC

unread,
Apr 6, 2022, 8:39:35 AM4/6/22
to Glowscript Users
I have downloaded Glowscript Offline 3.2 zip file, and I manipulated some of the code in order to load a python file without user input (user no need to write the code). 

Here is my attempt:

var text 
    function getHeader(exporting, fileExp) {
        // var text = GSedit.getValue()
        $.get("./Demos/" + fileExp, function (r) {
            text = r;
        })

However, it does not work because Javascript execute the code asynchronously. While the $.get is reading the python file, Javascript directly execute the other functions without waiting. Therefore, it makes variable text undefined. I have to click "run" button twice to run the code. Is there any method to solve this technical problem?

jQuery Glowscript.png

Bruce Sherwood

unread,
Apr 7, 2022, 2:23:52 PM4/7/22
to Glowscript Users
I don't immediately see a solution, but why not simply have the user click "Choose File"? The user doesn't have to write any code.

Bruce

Message has been deleted

KC

unread,
Apr 7, 2022, 9:23:43 PM4/7/22
to Glowscript Users
Because I want the user can select the sample without choosing the file. 
Selectsimulation.png

Bruce Sherwood

unread,
Apr 8, 2022, 12:56:46 AM4/8/22
to Glowscript Users
Why not just provide links to the programs stored at webvpython.org (=glowscript.org)? That's simpler than asking students to get the offline Web VPython and your files.  At any rate, I don't have any useful answers to your question.

Bruce

KC

unread,
Apr 8, 2022, 6:03:14 AM4/8/22
to Glowscript Users
Alright, that makes sense too. Thank you very much!
Reply all
Reply to author
Forward
0 new messages