Need Help for Engine Related Issues

0 favourites
  • 3 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Greetings everyone,

    This is my first post in this forum. I'm relatively new to this engine but not new to development. Firstly, I should give some credit to Construct 3—it is the best engine I have used so far for 2D development. The learning curve is so fast that I adapted and finished my first game in the first week. Then, I returned to my main project, which is a relatively large codebase RPG game. I have already implemented dungeon, enemy, and skill mechanics to construct and everything works like a charm. However, there are some issues/restrictions for which I couldn't find better solutions, so I am asking for your help if you have had similar needs before. Thanks in advance!

    1) My game has more than 200 skills for 4 different classes. The skill and combat system is already implemented, but I want my skills to trigger via functions instead of sub-events.

    Construct gives me two options:

    a) Function mapping, where I can use variables as function names and define them. However, I don't want to use this because I have to map every skill line by line on layout start, which is not ideal for this game.

    b) Calling functions directly from the event action with a popup dialog, where I can choose whichever I want. But this is not possible when trying to trigger functions names via instance variables values and i want my every skill is implemented as different functions name. So i can call them by name, on function "Slash", on function "Bite", on function "Heal" etc.

    Eventually, I couldn't find any solutions and had to put JavaScript in one event and fire this event when a player or enemy casts a skill:

    let Skills = runtime.objects.Skills.getAllInstances();
    let InvokenSkill = Skills.filter(i => i.uid === localVars.SkillUID)[0];
    try {
    	runtime.callFunction(InvokenSkill.instVars.SkillName.replace(/\s+/g, ''), localVars.SkillUID, localVars.EnemyUID, localVars.InvokedByPlayer);
    } catch(e) {
    	console.log(InvokenSkill.instVars.SkillName.replace(/\s+/g, '') + " skill mechanics must be implemented first to invoke. " + e)
    }
    

    This JavaScript is take instance of tapped skill via UID provided by function call. Gets SkillName as Function Name and fire it. Everything works.

    It works, but it seems like a bad implementation because this is the only scripting workaround in this project. All other events use Construct's editor predefined actions and logic for now at least.

    Do we have another solution to work for this without getting around it with JavaScript? If we don't have this kind of feature and I use these kind of scripting blocks in projects, I feel like eventually something will go wrong.

    I have another solutions to this but with more than 200 sub events this is so much ugly to be honest. Here it is;

    I want my skills as functions. Because this skills have additional mechanics for example Meteor Strike will trigger it's own additional function so can hit the it's AOE to different enemies. For example;

    2) Construct gives you two options to load a file via AJAX. First, you can "Choose a Project File" from the dropdown list, and this option never fails on any device as the file exists on any device. However, when I try to get a file from "Request URL," the preview works, but when I deploy it to an Android Debug APK and connect it to my phone via the developer interface, I find that calling SpawnPoints.json results in a 404 error. It doesn't matter if the JSON file is located in a subfolder or if it is named correctly.

    I tried with a subfolder (example/spawnpoints.json), without a subfolder (spawnpoints.json), camelCase.json, lowercase.json, CASED.json, underscores—everything I could think of regarding different file systems causing an issue about file naming. But no luck.

    Why do I need this? I have different dungeon layouts, each with spawn points in different JSON files. When a player engages in a dungeon, certain conditions run (biome, level, etc.). These conditions check one by one and determine which layout is chosen as set in the "Instance Variable." With this Instance Variable, I load spawn points of enemies in the dungeon, load ambient sounds accordingly, and load different event mechanics triggered by entering this dungeon, etc.

    But somehow Android can't locate the file if I call AJAX like this:

    What is the cross platform solution to call this ajax from project files but i should call them by instance variable not from dropdown list. I just need to pattern of the url structure to call this file from project files but couldn't figure it out.

    3) This is not an issue but a question. In Construct, you can name your functions whatever you want, even using spaces, and they still work. For example, on function "Player Hit GFX" works the same as on function "PlayerHitGFX". They both work correctly, but out of habit, I always define them as the latter. Why the Functions naming in Construct apart from JavaScript syntax rules and if we use spaces in function name like this will be different issues later on?

    4) When i set "Wait 1 Seconds" in main event block, all sub events waiting this timer to end in order to trigger. However when i use "Wait 1 Seconds" in the first sub event, only first sub event actions waiting this timer, other sub events of the main event triggers at the same time. I think this is the feature of engine and i should adapt. Although i want to hear your experiences and opinions why this is so.

    TL;DR

    1- I need a way to call function names by instance variable values. For example, I have a "Skills" family. In this family, there is a skill named "Slash." When I click the "Slash" button, it gets its instance variable SkillName and this name should trigger the function with this name's value. (The function "Slash" must be triggered via the value of the SkillName variable.)

    2- How do I make an AJAX call with right pattern from project files (not from the another server, but from the project files) without encountering a 404 issue on different platforms? It only works in preview mode and doesn't work on the Android APK.

    3- What is the difference between using on function "Player Hit GFX" and on function "PlayerHitGFX"? Will using spaces in function names cause problems later on?

    4- All sub events waiting for main event complete if we have a timer, when timer finishes all sub events fires at the same time if you don't chain them with else blocks. Note: This all sub events on same level. Please explain to me the logic behind why this is so.

    Sorry for the long post, but if you have time, could you clarify these issues for me? I would really appreciate it.

    Thanks.

  • 1. There is nothing wrong with this approach. (as long as you don't rename the functions). We do the same in our game - function names are stored in arrays, JSONs, instance variables etc. And we call them by name using a bit of scripting. Scripting in C3 is supposed to complement the event system. (although some people are making entire games with JS)

    I find it easier to save the function name in a local variable - this way you don't have to pick the object instance in the script:

    runtime.callFunction(localVars.funcName)

    2. File names are case-sensitive, I remember having the same issue. Rename the file to all-lowercase. You may need to re-import it to the project. And use all lowercase in AJAX request.

    3. Construct is very user-friendly! I believe you can even use emojis in function names, but I wouldn't do it :)

    4. Correct. The structure of events is very important. Construct runs all events from top to bottom. Any "waits" will delay the execution of actions in this event and nested sub-events. But they won't delay events which are on the same level.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hello dop2000, thanks for the fast response and I am glad to hear my approaches and assumptions are correct.

    In the mean time you are absolutely right about picking object in the script via picking by uid, instead passing my skill name as well from the event fire this. It's just a old OOP habit that i already have ID why the hell not to pick its name here haha. I'm still playing with codes and refactoring it and I will fix that as well. 2 line less in this script is better for debugging purposes. You are correct!

    By the way, about the function renaming, functions only be renamed if the SkillName instance variables value is changed and this wont be issue i would be aware and fix the function name accordingly if we change the skill name.

    Rest of the answers you posted i really appreciated and they removed some fogs in my mind.

    Cheers mate!

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