LoobyLoo's Forum Posts

  • Thank you for the detailed explanation! :) Now, I understand.

    Edit: Event sheets don't store arrays...? You're definitely misunderstanding something.

    πŸ˜… No, what I meant to say was about the Array Code, as shown below.

    + System: On start of layout

    -> AJAX: Request MY_JSONArray.json (tag "My_Array")

    + AJAX: On "My_Array" completed

    -> My_Array: Load from JSON string AJAX.LastData

  • πŸ˜… Okay

  • I do not understand your situation. Arrays are global. It doesn't matter what event sheet you refer to it from.

    Is it mandatory to place any action that depends on or fetches data from an array after this particular action?

    + AJAX: On "My_Array" completed

    -> My_Array: Load from JSON string AJAX.LastData

    If the answer is yes, then I've been mistaken all along, because I consistently store my arrays in a separate event sheet named "Array," without mixing them with any other code. :/

  • If I may, could you please assist me with this?

  • But in some cases, the array is stored in a separate event, and we need to call it from a different event sheet. In such situations, what is the recommended approach?

  • I have a particular function/action that I need to call multiple times, say x times. While I can manually achieve this by creating a button and clicking it x times, how can I set up a loop to accomplish the same?

    Tagged:

  • Thanks oosyrag It worked.

    Also if you're a beginner, my recommendation is to never use the wait action, ever.

    Please correct me if I'm mistaken, I used wait() for a specific reason. Here in my case, the C3 array is converted from a JSON array, If I don't include wait here, the array always shows 0. However, when I do include wait, the array provides the correct output.

    Or I should use here something else like "wait for signal" or "wait for the previous action to complete"?

  • Thanks for your response, I visited that page already, but I didn't understand it, so I asked the question. I'm getting on colsole

    a reference error: My_Array is not defined

    // My_Array is an array from c3 event (converted from JSON array),I put it on start of the layout, after using 1sec wait.
    
    var valueAt00 = My_Array.getAt(0, 0);
    
    console.log("Value at (0, 0):", valueAt00);
    
  • To manipulate global variables from the Construct 3 event sheet using JavaScript, we do

    // Fetched the data from the Construct 3 global variable to JavaScript
    var jsVariable = runtime.globalVars.c3Variable;
    
    // Store the data in the Construct 3 global variable from JavaScript
    runtime.globalVars.c3Variable = jsVariable;
    
    

    Similarly, What is the direct way to manipulate Arrays in Construct 3 Using JavaScript? What expression I should use?

    Let's say I have an array (JSON array converted into the native array) in Construct 3.

    I want to use JavaScript to add elements to the array, remove elements, or do other things with the array.

  • Construct 3 is really fun.

  • Thanks, R0J0hound, thanks for your suggestions.

    The three areas from which I could extract the text, the Array, Button Animation Name, and the local variable "String_LV"β€”all contain the same string. That's why I didn't create an instance variable, though I can understand why you're recommending that. I'll attempt to implement your suggestion to streamline the code.

    Initially, I believed it could be accomplished using a function due to the repetitive pattern, such as:

    "+ System: Pick BUTTON where BUTTON.AnimationName = String_LV"

    However, it appears to me now I might have overcomplicated things. I'll try to simplify first and then utilize a function. Thank you to everyone for your time.

    :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • oosyrag

    I still have no idea what your buttons are for.

    Sorry, I have updated my previous response with more details, could you please check that, Thank you.

    Also you have a wait for previous action to complete in there, which has no function without an asynchronous action before it. Which you don't, so you're probably misunderstanding something there. All actions are processed in order from top to bottom unless its specified as an asynchronous action.

    Yeah, I have an Array that is converted from a JSON array. At the start of the layout, when that condition is true, it's unable to fetch the Array, because for it needs some more time. So, I thought that instead of use wait 1 sec action, I would use this "wait for previous action ", but it turned out it is unnecessary, thanks for pointing it out.

  • Giving advice is a thankless task.

    I would follow the wish "if it works you don't need to get in the way".

    πŸ˜…πŸ˜‚

  • Hi, oosyrag, Thanks for your response,

    I think the overall code feels a bit lengthy. For example, there's a repetitive pattern eg.

    "+ System: Pick BUTTON where BUTTON.AnimationName = String_LV"

    However, some of these events also include a "Trigger once" condition. I'm not certain whether we can refactor these into a function to improve efficiency.

    Edit 1.

    Speaking about the code, its purpose is to auto Spawn icons and text on a button on the run time. When the animation name of the button matches the value of "String_LV",

    and for the text, "Button_Name.Button_Name_iv" matches the value of "String_LV", it will Spawn and reposition itself to the button.

    (TextVisibility_iv, Clickable_iv & ICONVisibility_iv are Booleans, if it is true, then it will be executed, in the given code, all are true)

    Having said that the same code will be used in multiple buttons (same button sprite but different instance of button), with only variations in local variables, I posted this question to explore avenues for enhancing efficiency.

  • The above code is working just fine. However, I'm wondering how I can make it more efficient. I'm still learning about functions, and I'm curious if I can enhance their efficiency using a function. Below is how I started. Any suggestions?