"Parameter must be constant" message when using a 'constant'

0 favourites
  • 9 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • Not sure whether to call this a bug or not, but it's definitely counter intuitive enough to me that it seems like it could belong here

    Problem Description

    On Function condition won't let me use a constant value as a function name.

    Steps to Reproduce Bug

    • In a new project, add the Function object.
    • Create a global constant text with an arbitrary name.
    • Attempt to create an On Function condition referencing the global constant as the function name.

    Observed Result

    We get a message saying "Parameter must be constant".

    Expected Result

    I would expect that referencing a global constant qualifies as the parameter being constant.

    Construct 2 Version ID


  • Not a bug... That's just how functions work in C2 they use the "cf_fast_trigger" flag which forces you to use a string represented as a constant not to be confused as a constant variable that is a string. I attempted to remove this restriction on my plugin with no luck. I ended up breaking the function plugin with out it and had to revert back. There is currently no method anyone is aware of to use variables of any kind as a function name declaration.

  • I wonder if there would be any issues if Ashley revised "cf_fast_trigger" to allow for referenced constants. Isn't it essentially the same thing since it still restricts the name to a constant that is never going to change during run-time?

    One obvious example for why allowing this is a good idea: one might use the Function trigger in multiple places throughout the code. Then, if it comes time to rename the function, it must be renamed everywhere, including all calls to that function. If a constant was being used in the condition and in the calls, renaming wouldn't be an issue.

  • I don't think we can fix this. The parameter must really be a constant - as in a string literal, not even a global constant. The problem if we allowed this is you could make an event referencing a global constant, run the game, then later at some point decide you don't want that global to be a constant any more, so you edit it back to be a normal variable and add some events to change it at runtime. Then the event you previously made is no longer valid.

    What's the benefit of using a global constant anyway? It doesn't seem like it saves you any typing or improves maintenance at all.

  • Ashley - It would be nice to have the function name show in the intellense list so we can select it, move on, and know it is typed correctly. Its pain to debug something that doesn't work because of a miss typed function name somewhere in our code (specially for those of us that use functions for everything). Unfortunately the work around for now is to have the function name both declared on the function its self and then again on a variable we use through out our code to avoid this issue. The constant variable would allow us to declare the function name only once and then be able use that variable both on the declaration of the function and then everywhere through out our code. If we decide to re-scope the project because our naming conventions change it is also much less work as the function name will change every where in code because its a variable in the project.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I guess the best workaround for neatness and improved maintainability is to define all functions in one event sheet, along with global constants to reference those function names. Whenever a function name has to change, simply make two changes - one to the trigger, and one to the global constant.

    That doesn't seem too bad I guess.

  • So I found how to make it work the way I want and allow variable names for function name declaration (yes i copied it and left the original in tact )...

    by removing the "cf_fast trigger" from the OnFunction Condition in the edittime.js

    AddCondition(0,	cf_trigger |cf_fast_trigger, "On function", "Function", "On <b>{0}</b>", "Triggered when a function is called.", "OnFunction");[/code:3qr3zex4]
    and then removing the fs.name from being passed to the trigger in the CallFunction action in the runtime.js. 
    [code:3qr3zex4]var ran = this.runtime.trigger(cr.plugins_.Function.prototype.cnds.OnFunction, this,fs.name);[/code:3qr3zex4]
    Granted I haven't fully tested to see what else might be broken but functions appear to work the way i want now and still work by name reference. I was wondering if you can tell me what benefit there is to having the cf_fast_trigger vs not having it?  Im sure its implied in the name but what am i actually losing by removing it?
  • It's not there for no reason: if you remove the fast trigger mode your project will have a performance penalty per 'On function' event used per function call, even from unrelated function triggers, and even if none of the other function triggers are actually used. Don't try to hack the engine if you don't understand it! It would be better to find a different solution.

  • So each trigger becomes an instance of the condition "OnFunction" and it loops through every trigger instance passing the name parameter to the condition until it returns true to know where the corresponding actions are to execute. But your pre building those "OnFunction" conditions somewhere else before the game is started so there is no looping. Interesting I guess that's why the alert() function i added to the "OnFunction" condition wasn't working when i trying to figure out how cf_fast_trigger works.

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