Functions, just a weird idea

0 favourites
  • 12 posts
  • 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

    <img src="https://dl.dropbox.com/u/23551572/C2/Functions/mockup.jpg" border="0">

  • 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?

  • 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

    Function: on "add"
      -> Function: return Function.param(1)+Function.param(2)

    This way anywhere in the event sheet you can do a:

    -> Set myVar to Function.add(5,4)

    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.

  • 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.

  • newt , Yann

    i see so its usually used on scores and some stats like xp and levels in rpg games ,right?

  • 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 (: )

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • ahh this will be very useful and complex for us XD , good luck with it and ill check rex's plugin :)

  • 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.

  • 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.

  • 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!

  • I think groups are pretty close to functions as is. Maybe add a way to change the group once its created (unless I missed it somehow once a groups created the only way to change start active or its name is to delete and remake it) and add maybe 6 optional text inputs to the group dialog to assign parameters. Then change the set group active event to allow you enter values for those parameters.

    Then treat the parameters as local vars when workin inside the group

  • Ashley yeah I see your point and I agree (: I just think there should be something that can be used when for instance I start typing the name of a custom function and then I can see how many parameters it needs.

    I thought that this way you could write "str2map(" and then see a tooltip of your parameters.

    aridale not really, functions not only isolate part of the code, but can be triggered many time on one event loop. Groups can't really. You could put a "repeat counter time" on your event with counter as a number variable that gets incremented each time you need to call the function, but then you'd have to keep the parameters in an array or a dictionary, and then store the return values, and then wait for the next loop to use them... pretty heavy...

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