Fengist's Forum Posts

  • Ajax request is returning me an array and setting it into JSON

    How to take the object itself from JSON, which has an array with objects inside, and extract the value from it by key?

    i want to write generator of shop cards from this data

    for example in this array is 6 items(objects) with their own data

    i need to generate 6 shop cards with this data

    is there any methods in construct or with JavaScript ?

    The easiest way I've found is to have your json contain a key/value pair where the value is a simple csv. Then, create an array and

    -> MyArray: Split string JSONValue with separator "," (type Number)

    That'll create a basic 1 dim array.

    If you have a pure JSON of the data you could also use MyArray.Load then enter var that contains the json.

    You could do your ajax call, make the value of a key to be the json you want to load, assign that value to a variable and then, load that variable into the array.

  • As you know Construct is great for teaching the basics of coding in a low code environment. Boolean logic, loops, arrays, etc. I've worked with a number of IDE's from Delphi to Unity. For rapidly developing an app, even with 40+ years of writing code, I keep coming back to Construct to do what I need.

  • Please how can I do it that when a person tries to play a game. My game can extract the game URL and the client id from a URL that has the game URL / client id and turn passes this information to an API endpoint that verifies if the person has access or not

    It lets the person play if it's successful but if the person doesn't have access, an error message is displayed

    What you're asking for is a user management system. And it's a bit more complicated than just passing a client ID. Anything that can be stored on the client, like a user ID, can be accessed and changed.

    There are a few ways to handle this. One is with Firebase and Google logins. I have no experience with either of those but lots of C3 creators use them.

    I opted for what you're describing with is an API to my own server and I wrote the code in PHP using MySQL. This took a good bit of work because you're going to need to handle user names, passwords, hashing, nonces, salting, email verification, forgotten passwords, account creation, etc.

  • You can do everything you want (memory limitations excepted) by using arrays. You don't need SQLite or Mysql or PHP. What I was suggesting was an easier way to generate the data for those arrays. You can always enter them manually. One thing to consider to reduce memory usage is to procedurally create an array map of your level then use that array to draw your level. Here's an example I did years ago using I think 12 image tiles to generate a procedural map. The array to create the map is just numbers.

    construct.net/en/forum/construct-3/your-construct-creations-9/procedural-archipelago-every-146271

    and the working demo:

    twistedvoid.com/c3examples/Castaway2

  • See the Learn JavaScript in Construct course or the quick-start guide which covers the basics of accessing objects from JavaScript. I'd also recommend using TypeScript which will catch coding mistakes like this for you so probably save a lot of trouble.

    Thanks Ashley. I try really hard to avoid using direct JS as I'm not that good at it. I have so many languages and API's in my head now for this and that IDE that I end up trying to jam Pascal into PHP code.

  • var emailObject = runtime.objects.EmailBodyInput.getFirstPickedInstance();

    var emailBody = emailObject.Text()

    you need to get an instance first.

    Thanks.

  • console.log(runtime.objects.EmailBodyInput.Text); // Log the whole object to see what it contains
    var emailBody = runtime.objects.EmailBodyInput.Text;
    
    if (emailBody) {
     emailBody = emailBody.replace(/\r\n/g, '\n'); // Normalize line endings
     runtime.globalvars.emailBody = encodeURIComponent(emailBody); 
    	consol.log(emailBody);
    } else {
     console.error("EmailBodyInput.Text is undefined.");
    }

    And I get EmailBodyInput.Text undefined. Know full well it contains text. Trying to clean up some line endings that aren't working as intended when I ajax them to my server.

    Thanks.

    Tagged:

  • Welll.....

    Manually entering data into an array would be tedious. And, any time you need to make changes or add things... ick.

    Manually creating a JSON would be even more tedious. Just making sure you got the syntax right.

    Assuming you don't have a lot of experience with MySQL or PHP, what I would do is something like this. And keep in mind, this is not an ideal solution but it would be a good starting place to learn about databases.

    First, I would download SQLite Studio (google it) and use it to create a database of the objects in the game. Depending on how you structured it, it would be dead easy to add levels, add new objects, etc. just by adding a new item to the table.

    After you have the database I would then look at using an SQLite to JSON converter like this one: mygeodata.cloud/converter/sqlite-to-json

    SQLite creates a db file that you'd upload to it. I've never used that site before so I can't promise it would work.

    Then, bring your JSON into the game, parse the crap out of it and stuff all that into an array.

    The advantage of that is, you could have a table for enemies, a table for asteroids and a table for drops and you could load each into separate arrays.

    That being said, if you have gobs of stuff to add, arrays do have limitations.

    I'm sure you could do it in firebase but, I've never worked with it so I couldn't tell you where to even start there.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Loopindex doesn't work in For Each element loops. Either use System For loop, or Array.CurValue expression.

    Actually, that's not even "For Each element" loop on your screenshot, it's "For Each instance".

    DOH!

    Thanks. Just used to php and throwing that array in there and expecting a foreach for each of it's elements.

    Knew I was doing something totally stupid.

  • And just as a test I set that EmailTitle to the MailDeleteArray.AsJson and it appears to be properly loading the CSV so... it must be in my concatenation.

  • Ok, I know I'm missing something just blatantly obvious here but for the life of me, it's kicking my ass.

    I have a JS in my HTML that's calling this Get Checked Mail ID function each time a checkbox is clicked. It's passing a csv of numbers to this function with each checkbox ID. Ex - 9,3,4,2,5

    I'm splitting that csv into an array and doing a foreach.

    What I'm trying to build is a URL with an array to post with ajax, similar to this:

    example.com/api The purpose of this function is to build that URL array and save it to a string.

    What I get from this code is the first element in the csv/array (delete_emails[]=9) and none of the others.

    I know the csv looks good passed from the JS. What I can't tell because the JS won't run in debug is whether the array is getting populated correctly or my concatenation is screwed up. Which is why for now I'm just setting that EmailTitle to the string it creates.

    Thanks.

  • If you are loading the js into an html element you can do this:

    parent.c3_callFunction("MyFunction", [MyParam]);

  • I'm a little late to this but, my suggestions are:

    1. Only work with a developer in the same country as you.

    2. Get a legal Non-Disclosure Agreement (NDA) signed.

  • Ok, only thing that comes to mind is that chrome has a habit of caching JS scripts, especially if you're pulling them in from a remote location. One of the old tricks is to add a version number to the JS file name... myjsfile10.js When you change that js, change the file name... myjsfile11.js. Chrome will see the new file name and fetch it instead of using the cached copy.

    Another thing you can do in the preview is to try hitting ctl-f5 or ctl-r. Both of those force the everything to reload including images and js files.

  • Just curious, have you tried sending your query as an ajax request? Don't forget to set your CORS header if you do.

    Which makes me wonder, have you checked the debug console to see if there are any errors. I know a CORS error in the AJAX won't return anything but it will produce a console error.

    I'm not using any mod rewrites but I am using wordpress as a game server. What I do with it is have it look for a specific /foo/bar in any incoming request and if that directory is in the url, I pass the query on to the game server code which returns a JSON. Otherwise, it hands back off to the wordpress code and displays the website.