Nilom's Forum Posts

  • Hey there!

    I want to store all of my relevant data like localization, ui position, button sizes for the mobile or pc version in a single JSON object.

    Is there a way how I can parse/load multiple .json project files into a single JSON object?

    For example load english_localization.json & interface_data.json & variables.json into Data (name of JSON object).

    So that I can do things like:

    Data.localization.main_menu.header
    Data.ui.pc.main_menu.header.x
    Data.ui.pc.main_menu.header.y
    Data.ui.pc.main_menu.header.font_size
    

    ...

    OR

    ...

    Data.ui.mobile.main_menu.header.x
    Data.ui.mobile.main_menu.header.y
    Data.ui.mobile.main_menu.header.font_size
    

    More specifically:

    Data.Get(".ui.mobile.main_menu.header.font_size")
    

    So for example a menus header text position could be set to:

    x:

    Data.Get(".ui." & platform & ".main_menu.header.x")
    

    y:

    Data.Get(".ui." & platform & ".main_menu.header.x")
    

    Where platform is either pc or mobile.

    Oh and my other question is: Is that a good practice?

    I imagine it being handy to have every data at one place instead of mixing json and global variables. I want to have a modular interface where I can use the same events with different pc/mobile values instead of having double the event count.

  • When a player collects a coin you add +1 to the variable coins. If coins are x (the number needed) you let the goal appear.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I got it to work.

    But I had to use runtime.objects.Language.getFirstInstance().

    Now I have two working solutions for the problem that I had.

    This is how the script looks now.

  • dop2000 & WackyToaster

    You two are awesome! Setting the variables to static fixed the issue! I just had to add that the logged_in variable has to be set to 0 afterwards.

    It's also odd that it does work outside the function.

    I guess it is because I ordered the last two events (that got skipped) as sub-events of the event block containing the promise script. If I'm honest I didn't know about setting the variables to static. In that cases I just made other events sub-events to prevent resetting, lol. But seems like inside functions that does not work compared to outside of functions. But with that knowledge I will use static variables instead of sub-events in the future.

    Thank you both!

  • You are right. I will thoroughly debug later and give an update.

  • But I tested and it works the same regardless of whether it's inside a function or not.

    Does this mean that there is something wrong with how I ordered the events?

  • You can easily test this by replacing "Wait for previous action" with "Wait 1 second".

    That still returns 0. :-o

  • I would suggest adding Browser Log after "Wait for previous action" action to check the value of logged_in variable.

    I will test that tomorrow. But what's odd is that it is working outside of this function.

    Edit:

    Just tested it and it seems like that inside of the function the wait for previous actions to complete is ignored. But it is not ignored if I use the exact same event structure in the button directly.

    Javascript await + wait for previous actions will wait until the script is finished. But for some reason it will not do this in a function.

  • Hey there!

    For the last 5-6 hours I'm trying to solve my issue that I have.

    It is a bit frustrating that the documentation in the scripting section is assuming that a programmer is reading it and not someone who might just be learning it. There is a lack of examples.

    I try to get a JSON objects contents via script. I mean the Construct 3 event object JSON.

    How can this be done?

    My JSON object is called Language because it houses the localisation. I read this and tried everything.

    	runtime.objects.Language.getJsonDataCopy();
    
    	var lang = runtime.objects.Language;
    	var copy = lang.getJsonDataCopy();
    	console.log(copy);
    	return copy;
    
    	var lang = runtime.objects.Language;
    	var copy = getJsonDataCopy(lang);
    	console.log(copy);
    	return copy;
    

    No matter what I try I always get getJsonDataCopy() is not a function. Doesn't matter if I use a script in the event system or if I call a function from the imported scripts.

    Please, how can I read the JSON data that is stored in Language?

  • Hey there!

    I want to turn my login events into a function because I want to add multiple ways of signing in. For example by button click, by pressing enter etc. and I just want to use a single function for that.

    Here is what the perfectly fine working login events look like:

    So now if I turn that into that function:

    The whole red marked part at the end is skipped. Even though I checked via console that the local var signed_in is indeed set to 1. Or if I put in wrong login information to force an error message (from mongodb) then error_message != "" will be ignored too.

    This is how the login button event with the function looks like:

    Why is that? I even tried using function parameters instead of local variables. And tried setting it to asynchronous, with and without a wait for previous actions.

    In order to circumvent the part that is skipped I'm implementing the skipped part inside the javascript snippet. The login part works just fine. But for the error messages I'm confused as to how I can access the key-value-pairs of my JSON object within javascript.

    I tried a lot of variations of

    runtime.objects.Language.Get("error_messages." & error_message)

    runtime.objects.Language.getItem("error_messages." & error_message)

    runtime.objects.Language[2]

    runtime.objects.Language["error_messages." & error_message]

    runtime.objects.Language["error_messages." + error_message]

    runtime.objects.Language[String("error_messages." + error_message)]

    runtime.objects.Language[String("error_messages." + String(error_message))]

    etc...

    This is what the modified login script looks like

    Please help with either getting the functions last part not getting skipped or with the part how I can retrieve the JSON object from script event. Thank you! :)

  • Looks like there is no action to change listbox type.

    What you can try is the new templates feature

    It should work with the set attribute action. For the input object I can use set attribute and as the attribute I can put the string "Type" and then put "Password" as the value and it succesfully changes the input object to password type. It is inconsistent that this does not work with the list object. Or maybe it does but we don't know the true attribute names.

    Anyways, thanks for the template suggestion. It is indeed a good workaround. I will stick with that!

    Inside the game you can get its type.

    Thanks but I need to change the type.

  • Hello together!

    I like to use functions for objects that I create regularly.

    Now my problem is that I do not know how the List objects type attributes are called internally. "List box" and "Dropdown list" do both not work if I set the type to these.

    Although the List objects types are called "List box" and "Dropdown list" in the properties inside the editor these do not seem to be the right type names.

    I tried to somehow log the lists javascript object to see if there is the type shown.

    Unfortunately, no. Or I can't read them.

    Does anybody know Ashley how I can see the available object attributes for a given object?

    Thank you in advance!

    Edit:

    I want to add that with the Text input object modifying the type at runtime did indeed work. "Text", "Password", "Email", "Number" etc.

  • I just found the answer very well hidden in the mongodb forums. The second reply.

    Just copy the function to importsForEvents.js and call it from catch(err) and pass err to it.

  • Hey there!

    I use the Mongodb Realm Web SDK in my project. When the user inserts wrong login data and presses login there will be an error message in the chrome developer log.

    But how can I get the error code in my app?

    async function loginEmailPassword(email, password) {
     const credentials = Realm.Credentials.emailPassword(email, password);
     try {
     const user = await app.logIn(credentials);
     console.assert(user.id === app.currentUser.id)
     return user;
     } catch(err) {
     console.error("Failed to log in.", err);
     }
    }
    

    This is from the Mongodb documentation but it just won't log the error nor an error code. Nothing.

    I found this and one of the answers included this but I don't understand it.

    Please can someone with more programming knowledge than me explain to me how I can get the error codes from Realm so that I can tell the user why login didn't work?

    Thank you very much!

    Edit:

    I found out that the second of the error codes indeed is from the console.error command. Now I just need to extract the actual error message and code.

    How can I turn the built in tokenat(text, index, separator) function into an actual Javascript function for the importForEvents.js scripts?

    That's what I have so far:

    function tokenat(text, index, separator) {
    	var result = text.substring(text.indexOf(separator) + 1);
    	return result;
    }

    But I'm too dumb to implement the index part for the case if there are multiple separators.

  • Any ideas?