Functions, just a weird idea

Discussion and feedback on Construct 2

Post » Mon Jun 25, 2012 10:19 pm

Hi,

As I'm making a level editor, I'm starting to really need a function feature.
I know, it's on Ash's todo list, and there's a plugin rex made and I'll probably give it a try.

But then I thought about how a function could work inside of C2.
I always thought that how it was made in CC was kinda awkward.
Putting function anywhere inside the main event sheet, it feel like it isn't their place.

So, what if, functions where a kind of hybrid between event sheet and object.
It would be a kind of event sheet, stored in a project folder but an event sheet which could have properties.
And some of these properties could be function parameters.
For the inside of the function it would look like an event sheet but where you can access these parameters like global variables. (and still access global variables)

It could look like that
Link to big image
Yann2012-06-25 22:22:08
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Mon Jun 25, 2012 11:01 pm

i don't know what you mean by function do you mean the expressions with objects? for example lerp(camera.x, player.x, x)
or there is another meaning of function on games creating?
B
45
S
15
G
6
Posts: 795
Reputation: 11,935

Post » Mon Jun 25, 2012 11:07 pm

@zsangerous if you used Construct Classic, there's a function object.

This object allows you to encompass some actions inside a function call this way
[code]Function: on "add"
-> Function: return Function.param(1)+Function.param(2)[/code]
This way anywhere in the event sheet you can do a:
[code]-> Set myVar to Function.add(5,4)[/code]
and myVar will be equal to 9.

I hope C2 will have his own function system soon, but for now, rex's function plugin seems to do the job well enough.
I just had this idea about function I wanted to share. Because I don't really like the way functions are lost in the event sheet in Construct Classic.

It's super easy this way to have some repetitive part of the code called from anywhere and instantaneously executed. Functions are better than using a trigger variable or groups because they are kinda out of the main event loop.Yann2012-06-25 23:10:46
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Mon Jun 25, 2012 11:16 pm

@zsangerous
Think of a function as if it were a generic state machine.
Rather than if variable = this, do foo, you can call the "do foo" part at any time.
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Mon Jun 25, 2012 11:22 pm

@newt , @Yann
i see so its usually used on scores and some stats like xp and levels in rpg games ,right?
B
45
S
15
G
6
Posts: 795
Reputation: 11,935

Post » Mon Jun 25, 2012 11:29 pm

@zsangerous
Nah my example is the simplest possible stuff you can do with function.
Functions in CC at least are pretty powerfull.
Some month ago I made a level editor in CC and I created "save" "load" and some other usefull function for my editor.
This way I could do a save anywhere in my event cheet, on click on a button, on a keyboard shortcut, when I change level "save" on the current before changing, etc
Really missing this functionnality. (well as I said, not exactly missing since there's rex's plugin (: )
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Mon Jun 25, 2012 11:33 pm

ahh this will be very useful and complex for us XD , good luck with it and ill check rex's plugin :)
B
45
S
15
G
6
Posts: 795
Reputation: 11,935

Post » Mon Jun 25, 2012 11:39 pm

You can use it to open a door, bring up a menu, etc.
Its also useful for some recursion when you add the ability to add data on the fly.
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Tue Jun 26, 2012 12:10 am

It seems like an interesting idea, although I kinda like the ability to put functions among the code, I think it's quicker to setup and debug. Using a group normally puts them off my way when needed.

By looking at your mockup I realized that you could just use event sheets to store function code and have a very similar situation with the current C2 features. You could either have one event sheet for all functions, or one event sheet per function. Then just include the event sheets when you need to use them.

The only thing that's necessary in the official plugin is guarantee support to calls between included event sheets.


And @zsangerous , think in functions like detours or shortcuts inside your code where you can interrupt your event execution flow for a while, call and execute another piece of code, then return to the same place it was before.

It's very useful for modular programming, where you make a piece of code that has a specific function that can be reused whenever you need that functionality.
Scirra Employee
B
129
S
45
G
15
Posts: 705
Reputation: 15,413

Post » Tue Jun 26, 2012 11:00 am

I'm afraid I'm not keen on the idea of showing them in the project bar or giving them properties - I think a single function is too small a thing for that. It would be like giving every single event properties and an icon in the project bar. It could get very confusing!
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,468

Next

Return to Construct 2 General

Who is online

Users browsing this forum: 8tomo8, akash15 and 10 guests

cron