Archelux's Recent Forum Activity

  • AHH, \n, not /n. My bad! Thank you for the quick answer!!

  • I have a script within an event block that calls an imported javascript function that is within an if statement.

    This function does a few things, but among others its meant to fill the text of an object with:

    let var = "Test";

    let inst = runtime.objects.Object.getFirstInstance();

    inst.text = "newline &" + var + "& newline";

    The result I would like:

    -----

    Test

    -----

    The result I get:

    -----

    newline &Test& newline

    -----

    I have also tried Newline, /n and [br][/br], but they just get typed out.

    This part is within an imported function called within an if with information that said function calculates. I know newline would work if I set the text via event, but I really wouldn't want to make 5 new global variables that I will only use once, and spread the whole thing over a bunch of other functions just because of this missing syntax. Or copy paste a large function into the scriptblock of the event.

    Is there any way to add a text including new lines to a text object with javascript?

  • Nevermind, I found that it needs the rgb values as floats. Is there a reason for this...? I couldn't even find the name of such an rgb system. Dividing each value through 255 gave me colors, but not the correct ones.

  • Sorry to be here again, but unfortunately colorRgb isn't working. There are no more errors, but the Sprite remains gray. here's what I have (I have checked what the console logs print and copy pasted it over):

    console.log("pricolor is: " + pricolor); // PRINTS pricolor is: 10439f,874ccc,c65bcf,f27bbd

    // PRIMARY

    switch (pripattern)

    {

    case "Plain":

    const pricolor0 = hexToRgb(pricolor[0]);

    console.log("RGB color to use is: R:" + pricolor0[0] + ", G:" + pricolor0[1] + ", B:" + pricolor0[2]); // PRINTS RGB color to use is: R:16, G:67, B:159

    let priinst = runtime.objects.CR_FelNoc_PriColor.createInstance(5, positionx, positiony);

    priinst.colorRgb = [pricolor0[0], pricolor0[1], pricolor0[2]];

    // Sprite remains gray. No errors or Warnings.

    break;

    }

    The instances are created and placed, so they definitely exist.

  • I find the documentation sometimes difficult to navigate, as I checked IObjectInstance and the Sprite API and didn't find anything. Thank you very much for the answer!

  • I have a project in which I am layering different types of Sprite instances in different colors. The function is in a separate Javascript file and then imported for use in events.

    Essentially I have an instance of a sprite that is simply a solid gray color. In a Javascript function, I create a new instance of this sprite in the correct position (Ive tested this, and it works), and now want to color it in with a specific rgb value. The sprite should remain solid and non-seethrough. (Ideally it should retain its alpha value to not look pixelated.)

    I've seen the function setColorRgb() somewhere, but using it says it's not a function, so I may have that wrong. What would the correct function be to do this?

    Codebit (Yes, I do pass runtime from scripts where I use the function.):

    switch (secpattern)

    {

    case "Plain":

    const seccolor0 = hexToRgb(seccolor[0]);

    let secinst = runtime.objects.CR_FelNoc_SecColor.createInstance(6, positionx, positiony);

    secinst.setColorRgb(seccolor0[0], seccolor0[1], seccolor0[2]);

    break;

    }

  • Got it, I think I found the section of that part that I was looking for - I wasn't aware Array objects also worked with instances this way. Thank you for the answers!

  • Having adjusted my code to this:

    console.log("Entered Printing function.");

    let stringtemp = "";

    for (let i = 0; i< 26; i++) // 9 elements, index goes to 8.

    {

    stringtemp = "";

    for (let j = 0; j< 19; j++) // 20 elements, index goes to 19

    {

    stringtemp = stringtemp + "<" + runtime.objects.ARRAY_TotalDLs.getAt(j, i) + ">";

    }

    console.log(stringtemp);

    }

    I now receive a "TypeError: runtime.objects.ARRAY_TotalDLs.getAt is not a function".

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I can declare an empty array called the same as the array object, but upon declaration, it will be empty, as it was just made and is in my understanding not connected to the array object into which I loaded in my data.

    Is it then not possible to retrieve the data of the array object from javascript? Or is there a special declaration that will connect the newly declared array with the array object I already have?

  • Firstly, thank you for the answer! I am definitely still dealing with this issue.

    Essentially I use javascript and fetch functions to communicate with a server to receive JSON data and then load it into the array object, but now need to console log the entire array (and will need to access specific points of it later anyway) to check if all data went in correctly.

    My code in that code block (within an event sheet) looks like this:

    console.log("Entered Printing function.");

    let stringtemp = "";

    for (let i = 0; i< 26; i++) // 9 elements, index goes to 8.

    {

    stringtemp = "";

    for (let j = 0; j< 19; j++) // 20 elements, index goes to 19

    {

    // Why does this function call not work?

    stringtemp = stringtemp + "<" + ARRAY_TotalDLs.getAt(j, i) + "> ";

    }

    console.log(stringtemp);

    }

    I have already gone through the javascript Construct tutorial, as well as read the Array API documentation. I find them to not be precise/detailed enough on this, personally (Mostly lacking practical examples).

    Does this mean I cannot access the array that I created using Constructs inbuilt features? As in my understanding, if I declare a new array within javascript, it will be an empty new array, but I need the information I loaded into the array object beforehand.

  • Older thread, but I have a similar issue, except I am already using getAt.

    My array is called ARRAY_TotalDLs. It has been filled with JSON data beforehand using the inbuilt Load. The array is global.

    I want to access it at specific numbers, using the variables j and i.

    So I do:

    Array_TotalDLs.getAt(j,i);

    I get a "ReferenceError: ARRAY_TotalDLs is not defined".

    I have checked the spelling numerous times, but with no luck, including copy pasting the name directly to ensure no errors. The Array is created from the beginning, so it most definitely exists. I have console logs that ensure that I enter the code block and that the JSON data is correct, and Load seems to succeed.

    What am I doing wrong?

Archelux's avatar

Archelux

Member since 6 Apr, 2024

None one is following Archelux yet!

Trophy Case

  • Regular Visitor Visited Construct.net 7 days in a row
  • RTFM Read the fabulous manual
  • Email Verified

Progress

3/44
How to earn trophies