Share a set of color values between projects

0 favourites
  • 15 posts
From the Asset Store
Full game Construct 2 capx code source to post on Google Play
  • I have many projects that I want to all share the same set of random background colors

    choose (rgb(255, 154, 162), rgb(255, 183, 178), rgb(255, 218, 193),rgb(226, 240, 203),rgb(181, 234, 215),rgb(199, 206, 234),rgb(175, 228, 254))

    I want the values to all be referenced from one external file, so that if I change the colors, it applies to all projects without me having to do anything further. Can someone suggest a good strategy for doing this? Everything I've tried has not worked.

    Thank you

  • Any ideas? I'm sure it must be possible. Any help would be greatly appreciated. Thank you.

  • You'll have to put the file somewhere (e.g. a server) and request the file via ajax. The file could be for example a dictionary or array.

    1. Load file via AJAX

    2. Load it into array/dictionary object

    3. Access the values as per the documentation

    For a dictionary it would look something like this

    choose(rgb(Dictionary.get("r1"),Dictionary.get("g1"),Dictionary.get("b1"), Dictionary.get("r2"),.....))

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for your reply.

    I have a json file uploaded for testing purposes at vikasapp.org/res/script/randomBgColors.json

    with these contents, for testing

    {

    "colors": [ {"r": 255, "g": 0, "b": 0}, {"r": 0, "g": 255, "b": 0}, {"r": 0, "b": 0, "g": 255} ]

    }

    and I have a barebones .c3p project here on dropbox

    that loads this json via ajax, and has a dictionary and array object, but I really don't understand what to do after that. Any assistance is greatly appreciated. Thank you.

  • This would be how you load it into the array. Then check the documentation of ajax and arrays (and maybe some of the build in example projects)

    But you'll have to fix a couple of things with your file. IIrc it has to be hosted on https otherwise the request fails. You may also need to set CORS (google it). Also Construct arrays look different, so look that up also in the documentation.

  • Ok, it is https and I have the second bit in place. What comes next if I can ask? I'm sorry I am not very technically competent.

  • You don't have to be technically competent, you have to become technically competent :)

    construct.net/en/make-games/manuals/construct-3/plugin-reference/array

    So it will look something like this

    choose(rgb(Array.At(0,0),Array.At(0,1), Array.At(0,2)), rbg(Array.At(1,0), Array.At(1,1),....))

    Check the console for errors (F12 in chrome) it will tell you if your ajax is working or not.

  • I got a CORS error, which I fixed by updating the .htaccess, and that's not happening anymore. I get one error in the console.

    Failed to parse JSON: SyntaxError: Unexpected token 'A', "AJAX.LastData" is not valid JSON

    at JSON.parse (<anonymous>)

    at ArrayInstance.JSONLoad (runtime.js:23:47)

    at Action._RunObject_ParamsConst (action.js:23:451)

    at EventBlock._RunActions_Fast (eventBlock.js:26:208)

    at EventBlock._RunAndBlock (eventBlock.js:24:415)

    at EventBlock.Run (eventBlock.js:21:393)

    at EventSheet._ExecuteTrigger (eventSheet.js:19:154)

    at EventSheet._TriggerForClass (eventSheet.js:13:302)

    at EventSheet._Trigger (eventSheet.js:12:205)

    at EventSheetManager._Trigger (eventSheetManager.js:15:90)

  • It's saying it's not a valid json file

    {

    "colors": [ {"r": 255, "g": 0, "b": 0}, {"r": 0, "g": 255, "b": 0}, {"r": 0, "b": 0, "g": 255} ]

    }

    I feel like it's close.

  • If anyone can help with this, I have spent like 4 hours trying to get it to work to no avail.

  • Construct uses somewhat different syntax for Arrays. Try

    {"c2array":true,"size":[3,3,1],"data":[[[255],[0],[0]],[[0],[255],[0]],[[0],[0],[255]]]}
  • I put in a text box to confirm AJAX.LastData and it is coming through but not the numeric values, and I get the same error in the console.

    runtime.js:23 [Construct] Failed to parse JSON: SyntaxError: Unexpected token 'A', "AJAX.LastData" is not valid JSON

    at JSON.parse (<anonymous>)

    at ArrayInstance.JSONLoad (runtime.js:23:47)

    at Action._RunObject_ParamsConst (action.js:23:451)

    at EventBlock._RunActions_Fast (eventBlock.js:26:208)

    at EventBlock._RunAndBlock (eventBlock.js:24:415)

    at EventBlock.Run (eventBlock.js:21:393)

    at EventSheet._ExecuteTrigger (eventSheet.js:19:154)

    at EventSheet._TriggerForClass (eventSheet.js:13:302)

    at EventSheet._Trigger (eventSheet.js:12:205)

    at EventSheetManager._Trigger (eventSheetManager.js:15:90)

    Project File

    json file

  • You try to load "AJAX.LastData" as a string, not as a value. Do it without the ""

  • That was it. Thanks so much for your help.

  • For anyone that might read this in the future, this is what was required in the end. I love how simple it turned out to be.

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