Suggestion: Functions

Discussion and feedback on Construct 2

Post » Wed Apr 17, 2013 9:47 pm

Is there a reason I cannot select from a list of my functions? It's not always easy to remember the names. I have to keep looking around for them. Would be nice if I could at least see a list of them somewhere. ;)
Jack of all trades, and master of some.
B
29
S
9
G
7
Posts: 174
Reputation: 7,601

Post » Wed Apr 17, 2013 11:19 pm

This has been proposed a couple of times, not just in regards to functions but anything that is user defined and identified by name, variables, objects, families, etc... I am hoping it makes it in at some point...
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,428

Post » Thu Apr 18, 2013 1:30 am

If you can only pick from a list of existing functions, there needs to be some different way to create a new function. That makes it a little more complicated than just adding, say, a dropdown for existing layouts. It's on the todo list though.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Thu Apr 18, 2013 1:50 am

Until an in engine solution is created. I have another suggestion.

Use and Array, but not the Array fields. An Array is considered a global object. An Array can have variables. There can be more than one Array. So let me write a psuedo example of what you can do.

This is your array object. It has the name Colour
Colour // this is your array object
var fnPickColour = "colourPickColour"
var fnGetColour = "colourGetColour"
var fnFoo = "colourfoo"


this is the sample OnFunction Calls. Ie the function event. Instead of writing out a string. Instead you reference a variable.
OnFunction(Colour.fnPickColour)
OnFunction(Colour.fnGetColour)
OnFunction(Colour.fnFoo)


When calling the function. as you can see now. Your not writing a string.
Function.Call(ColourFn.fnFoo)


Best of all if you
Function.Call(Colour.fn)
a drop down list of the variables stored in the arry(with the array function expression). By putting somekind of camel hump notation after the period similar to fn(FuNction) the dropdown list will sort out.

It's not perfect, but it does work. Also it also requires the developer to create the functions prior to there use.
B
87
S
18
G
9
Posts: 2,455
Reputation: 14,834

Post » Thu Apr 18, 2013 3:23 am

Not a bad work around actually. A little extra work, but it should do for now. ;)

Edit: For those reading, I just realized that I can also "group" some logic in an "on created" event - so as far as "grouping" sprites together" goes, that helps.JoyfulDreamer2013-04-18 05:45:17
Jack of all trades, and master of some.
B
29
S
9
G
7
Posts: 174
Reputation: 7,601

Post » Thu Apr 18, 2013 12:59 pm

I use global constants to hold function names - then when I need to call a function, I can just pick it from my globals list. Has the added benefit of allowing me to enter in a comment that tells me what the function does, what it returns and/or what parameters it takes.

I usually keep an event sheet called Function Headers, and try to stick to a naming convention like F_FUNCTION_NAME - that way, when looking through globals, I can see all of the functions grouped together. Then I can quickly look at the comment to see how to use it properly.

It's a bit of extra work (and some overhead for the globals as well), but definitely helps to keep things organized. Of course, some sort of built in method of organizing functions would be awesome :)rogueNoodle2013-04-18 12:59:49
B
9
S
3
G
4
Posts: 63
Reputation: 3,083

Post » Thu Apr 18, 2013 5:59 pm

rogueNoodle. I thought about globalization the function names. It works really well. The benefit is that the it get's to the function string faster. However, I felt the benefits of using an Array work out a little bit better. I'm not doing this to say golbal function vars are wrong. Just weighing in the difference so people who like both can compare for their needs. If you can add anything that I may miss please do so :)

Also I change my mind. Instead of an Array. Use Dictionary instead.


Global Function names
+ Function names are type safe
+ No require "" string ends
+ Short naming conventions allowed
- does not provide autocomplete(as far as I know)
- adds to the variable drop down list

~ Stronger notation for organization(if desired)
~ fantastic for smaller projects or fewer features


Object Function names
+ Function names are type safe
+ No required "" string ends
+ objective naming convention for organization
+ provides on function name auto-complete(ie "object.xxxx" )
+ Dictionary can provide it's own variable storage for runtime data
- does not allow for short naming convention
- functions are mixed with object properties and expressions

~ not bound to the event sheet
~ maybe more overhead for smaller projects than it's worth.



Looking at this. I wish I started my current project using these design guide. I was neck deep into current development before thinking of this.

Personally I would like an open Object that we can treat as a custom defined class. Then again the dictionary works really well except for cluttering up the expressions for the object.jayderyu2013-04-19 18:54:51
B
87
S
18
G
9
Posts: 2,455
Reputation: 14,834

Post » Fri Apr 19, 2013 3:24 pm

@jayderyu - That looks about right. The project size definitely plays a factor, as I'm starting to find adding globals for every function is a little tedious. I actually didn't think it was necessary to include an event sheet in order to have access to the globals, but to be honest, I'm not sure why I thought that...

Having a better look at your method, I definitely see the benefits in it - will probably use that method for my next project.

B
9
S
3
G
4
Posts: 63
Reputation: 3,083

Post » Fri Apr 19, 2013 3:40 pm

@jayderyu ; @rogueNoodle :
You don't need to include an event sheet to have access to global variables defined in it. Those global variables are global to the whole project.

The dictionary though needs to be set as a global object, possibly created in the very first layout of your project and filled at that moment. Once it is filled, no need to do it again.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Fri Apr 19, 2013 6:53 pm

Yep. I stand corrected. That was an over sight of my part :P
B
87
S
18
G
9
Posts: 2,455
Reputation: 14,834

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 1 guest