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

Bugs will be moved here once resolved.

Post » Mon Jun 16, 2014 10:24 pm

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 :P

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
r170.
Image
B
10
S
3
G
2
Posts: 196
Reputation: 2,053

Post » Mon Jun 16, 2014 10:31 pm

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.
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Tue Jun 17, 2014 12:39 am

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.
Image
B
10
S
3
G
2
Posts: 196
Reputation: 2,053

Post » Tue Jun 17, 2014 12:15 pm

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.
Scirra Founder
B
387
S
230
G
87
Posts: 24,249
Reputation: 192,240

Post » Tue Jun 17, 2014 4:01 pm

@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.
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Tue Jun 17, 2014 4:32 pm

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.
Image
B
10
S
3
G
2
Posts: 196
Reputation: 2,053

Post » Tue Jun 17, 2014 7:32 pm

@Ashley.. 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
Code: Select all
AddCondition(0,   cf_trigger |cf_fast_trigger, "On function", "Function", "On <b>{0}</b>", "Triggered when a function is called.", "OnFunction");


and then removing the fs.name from being passed to the trigger in the CallFunction action in the runtime.js.
Code: Select all
var ran = this.runtime.trigger(cr.plugins_.Function.prototype.cnds.OnFunction, this,fs.name);


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?
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Tue Jun 17, 2014 10:48 pm

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.
Scirra Founder
B
387
S
230
G
87
Posts: 24,249
Reputation: 192,240

Post » Tue Jun 17, 2014 11:35 pm

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.
B
20
S
7
G
1
Posts: 221
Reputation: 2,077


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 4 guests