Moving script to support Modules

0 favourites
  • 3 posts
From the Asset Store
Comprehensive localization solution for Construct 3 projects, no addons required!
  • So, I am trying to update my very old javascript Pop-up Calendar script to work with modules... I have read through the documentation many times, and have it pretty close to working. The only problem is that clicking on any of the calendar cells needs to call the f_tcalUpdate function, but that happens at the global scope where it doesn't know anything about my script.

    Can anyone help me get that function to work?

    here are two versions of the script: the first one is the one that I am trying to fix

    https://www.rieperts.com/games/forum/PopupCalendar.c3p

    this second one is the pre-module version that works fine in the R225 stable release

    https://www.rieperts.com/games/forum/PopupCalendar_225.c3p

    Note: if you run either of these in preview, the console will show error 404 messages on the calendar images, but it will still work fine. if you export the project then the images show up without the errors.

    they way the script is supposed to work is that when you click on the textInput field, a calendar will pop up under it to allow you to select a date. at the top there are buttons for Prev Year, Prev Month, Next Month, Next Year (but those buttons don't show in preview mode although they still work).

  • To put something in the global scope, you can use "globalThis.somethingGlobal = someObject", so in your case, in the "OnBeforeProjectStart" event, add this :

    	globalThis.f_tcalUpdate = f_tcalUpdate;
    

    Now because JS module are in strict mode, another correction need to be done in your tcal.js file. A variable can't be used before declaration so line 148 is invalid. Just add "const" in front the line and it should work.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Awesome!! thanks, that works perfectly.

    I was trying various ways to use globalThis but I obviously wasn't doing it correctly.

    Now I can move past r225. :) The next part I am working on is creating a PDF. I got jsPDF working yesterday but it requires modules while this old script required classic mode. So I was stuck with two scripts that wouldn't work together.

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