Global scripting variable, or better solution?

0 favourites
  • 6 posts
From the Asset Store
Globals 2.0
$3.60 USD
10% off
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • Hi, I am back to C3, I am a coder ar heart and I love this feature.

    In particular I can finally create array of arrays, the problem is that I do not know how to work with them, since, afaik there is no official way to use "proper" arrays in c3.

    I have a function with a looooooong script that generates a set of coordinates according to a complex algorigthm, it returns something like:

    ```

    [

    [10, 200], [320, 760], [754, 210], ...]

    ```

    I need to access said array in c3 to spawn objects.

    ```

    const currentSet = hackGlobalPunchesCoordinates.shift();

    runtime.objects.punch.createInstance(0, currentSet[0], currentSet[1], false);

    ```

    I have declared hackGlobalPunchesCoordinates at the beginning of the sheet as:

    ```

    var hackGlobalPunchesCoordinates = [];

    ```

    But I get a ReferenceError: hackGlobalPunchesCoordinates is not defined

    Is there a proper way to do this?

    The issue here is that the function that generates the coordinates need to be called before and away the spawn object routine.

    I would also be very happy to have a way to use array of arrays officially, as far as I can see you only support array of numbers, strings and bools

  • The variable probably does not have global scope. Make sure it's a property of globalThis, i.e. globalThis.hackGlobalPunchesCoordinates, to ensure it really is accessible everywhere.

  • The variable probably does not have global scope. Make sure it's a property of globalThis, i.e. globalThis.hackGlobalPunchesCoordinates, to ensure it really is accessible everywhere.

    Hi, Ashley, I want every new JS page to have access to the tick and layoutstart func. What am I supposed to do. The current practice is to addListener < tick > and < layoutstart > on the <main.js> page to connect each new page. Is there a more convenient way..

  • I'm not sure why you're asking. Isn't using a single main.js script already the most convenient way?

  • I'm not sure why you're asking. Isn't using a single main.js script already the most convenient way?

    Because every page has some method that needs to be initialized or executed in tick. I don’t want to cram all the different page methods into Main. JS inside. Is there a better way?xd

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Construct content always runs in the same page.

    If you just mean ways to organise your code, modules are good for that.

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