Functions in intellisense doubling by name

0 favourites
  • 13 posts
  • Problem Description

    Basically when you make a function for example named "TestFunction" and then copy paste it, you get anothre "TestFunction" instead of "TestFunction2"

    at runtime if we call "TestFunction", both the copied and original ones are called which is clearly wrong since there should exist in global namespace only 1 function of the same name.

    Attach a Capx

    https://ufile.io/6yymv

    Description of Capx

    When sprites collide you will see that both functions get fired at the same time, due to same name, which should be prohibited from making.

    The result should be 1 in variable, but it's 6 due to both functions firing.

    Steps to Reproduce Bug

    • Step 1 - create a function in event sheets that does something
    • Step 2 - copy paste the function - the name stays the same (bug! in global namespace there shouldn't be 2 functions of the same name)
    • Step 3 - rework 2nd function to do something else and call it from somewhere - both functions get fired (wrong!)

    Observed Result

    Both functions of the same name are fired, leading to bugs and errors in event sheet and runtime. Also only 1 is given as a choice at design time though there are clearly 2 functions existing.

    Expected Result

    I expect c2 to warn me of existing name of the function or when copy pasting to add a number or sth at the end to differentiate them.

    Affected Browsers

    • Chrome: YES
    • FireFox: YES
    • Internet Explorer:YES

    Operating System and Service Pack

    Win 10 latest

    Construct 2 Version ID

    C2 r259, latest version

  • I think this is by design.

    There are situations where you might need multiple functions with the same name.

    Say, you can have different event groups (KeyboardControls, MouseControls, GamePadControls) and a function named "FireWeapon" in each of them.

    Only one of these groups will be active, so you can call "FireWeapon" function from other parts of your project and don't need to worry about the selected control type.

  • no, that's a bad design.

    you can basically have 3 active groups then with the same method, let's call the method "Open",

    when something Calls Open - it calls all 3 Open methods, though only 1 should be called (the specific one).

    this causes more problems, especially if Open method handles items:

    • if item doesn't exist it would cause an error
    • if all 3 are run at the same time it is a performance problem (even though 2 would not do anything for example, or you expect only 1 to run)
    • when designing your code - when you call method - it offers only one Open (but which one are you calling? )

    additionally, since functions are GLOBAL, there should be a restraint to have 2 functions of same name in GLOBAL namespace, that's like the principle of programming.

    if they could be separated by groups or etc, then it would be ok (like having a Class with a method), but you don't have.

    and finally.. i see no problem calling different methods different name... if you have a method that does something called from 3 groups - make 1 method with 3 calls (in each group 1 ). And if you have 3 methods that have the same name and are spread throughout groups - call them differently. For example Open1, Open2, Open3 etc.. (or a bit smarter OpenDoors, OpenWindows, OpenChest etc.. )

    that's called polymorphism and basically c2/c3 does that through families but it does it badly.. or doesn't even do at all. so yeah..

  • If you have three "Open" functions and all three are called at the same time - that's poor project design, not a C2 issue.

    Construct does many things differently from "real" programming languages, but personally I like how flexible functions in C2/C3 are.

  • C2 should prohibit having 3 "Open" functions. because when you do "call function" it shows only 1 "Open". But you:

    1. don't know which of the 3 you are calling

    2. have a shitty design of the game

    3. have a editor that doesn't recognize the difference between all 3 Opens because they're in global namespace.

    and basically fixing 3 fixes 2 and 1. Also , the editor could (like good editors Visual studio or etc) differentiate functions of the same name that HAVE parameters and those that don't, because that's actually 2 different functions then.

  • I'm still not entirely sure whether this should be regarded as a bug or a feature request.

    With that said, the thread involves some points that is quite intriguing in terms of Construct 2 and Construct 3's design.

    Duplicate Functions

    In regards with the allowed upon duplication of functions on Construct, it seems more of a feature rather than a limitation on the editor's end. [It seems that JavaScript doesn't implement this.] Even though, multiple functions are still beneficial and more like a bonus feature.

    It is more apparent on larger projects, on Construct 2. In which case, modular designs are necessary to maintain the effectiveness, efficiency and management of the structuring of each independent features on projects where in duplicate functions can be used to signal independent protocols in the designed systems.

    Imagine a project with different independent branch of features. "Load", "Initialize", "Queue", "Draw" and "Transform".

    These are independent from the actual program functions like a framework, only that it is generalized for the purpose of the extending the program.

    The problem here is for example, how to communicate with each branches with only a single method and not make redundant method nodes.

    This comes the benefit of creating a single method and re-using the same function for each branch. And if there were parameters, the benefits would make it more obvious.

    This is an example where duplicate functions make it easier for development, especially on larger projects.

    And a simple duplicate function is a small price for the huge benefits it can offer.

    Function Scopes

    In regards with the Function Scopes, that is something I would like to see on Construct. I think it may not be possible anymore on Construct 2 but it would be nice to see this on Construct 3. Like how local variables are scoped by groups, it would certainly help both in the user & project management and function loading & prediction on the editor if the Functions are scoped globally and locally too.

  • Variable x=this

    onfunction(myfunction), do foo

    Variable x=that

    onfunction(myfunction), do some other foo

    Variable x=these

    onfunction(myfunction), do some other foo too

  • Ashley when do bugs get checked? it's been almost a week, noone took a look yet

  • Ashley when do bugs get checked? it's been almost a week, noone took a look yet

    Quote from Bug Report Requirements:

    [quote:15ybrsu6]

    Why haven't you responded to my bug report yet?

    We do look at every report, but developer and release schedules mean we may not get round to it immediately. Please allow a few weeks for it to be investigated.

    If you are waiting, you can improve the chance it is resolved when a developer does get round to it by carefully reviewing these guidelines and providing as much useful information about the problem as possible. If you are missing anything, you may end up waiting a few weeks for a reply simply asking for the missing information, and then you're waiting again.

  • This is currently by design. The function events are based on triggers. You can have multiple triggers such as more than one "On start of layout" trigger, and so you can have multiple "On function" events, it's pretty much as simple as that. I agree it would be better to redesign functions to only allow one function event, but this would be a major change and would not happen for C2. At some point we'll redesign the way functions work in C3 and think about it then, along with other ideas like named & typed parameters.

    Additionally it's very difficult to change anything like this so late on. Functions have been around for years, and there are likely many projects that depend on having multiple function events, tutorials that describe using them that way, etc. If we change it and break all these projects, the breakage is far worse than any improvement for fixing a quirk of functions, so it's not worth it. If we change it but allow existing projects to keep working the same, we've not really fixed anything, and it's an additional source of confusion ("why can't I make a new project the same as my old one" etc).

    So closing as by design / won't fix.

  • ok, thanks Ashley

    I presumed this answer would be what I get.

    Is it possible to at least "upgrade" intellisense to show each function instead of distinct of all functions in the project ( when you have 2 functions named "Test", intellisense shows only once "Test")

    it's a bit confusing, at least in the debugging sense (i was looking for bug 3 hours before i found that i've accidentaly had the same function twice)

    that shouldn't be a big upgrade, or?

    zenox98 - sorry about that, i've followed the guidelines when writing first post, i guess i forgot about it

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • There's no point listing two options in intellisense because they both do the same thing. It would also imply that you're only triggering one of the two "on function" events, but it doesn't work like that, it'll always trigger both.

  • True, but they don't have to do the same thing, and have the same name. That might be used as a feature, but also misused.

    In terms of debugging it would be easier to find out that you have a duplicate, and those who want both to run will pick any anyway.

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