How do I use function maps?

0 favourites
  • 9 posts
From the Asset Store
A template which allows you to customise the controls of your game.
  • Hi everyone, I'm new to Construct and programming in general.

    As stated from the title, how do I use function maps?

    I understand the use of functions and I have read the example on mapping RedFunction/BlueFunction/GreenFunction but I can't seem to wrap my head around it's purpose and how should it be used.

    Can anyone please enlighten me?

  • Previously you could call functions by an expression of their name, e.g. "Call myVariable". In this case assume "myVariable" could be one of "foo", "bar" or "baz", and so it calls the function according to the provided string.

    The new builtin functions don't support this. Instead you separately associate a string with the function. E.g. associate string "foo" with function Foo, associate string "bar" with function Bar, and associate string "baz" with function Baz.

    Then you call a function by its string with the "Call mapped function" action. So you'd use "Call mapped function myVariable", and it calls either Foo, Bar or Baz based on whether the string is "foo", "bar" or "baz".

    So it basically does the same thing as calling a function by an expression of its name, but with a different approach. If you want to pass parameters, it also has an option to forward parameters from another call. The benefit is now 'Find all references' is accurate, and you can safely rename functions without breaking anything.

  • Hi thanks Ashley for the added explanation.

    re maps, I Ive got it now except how to pass multiple parameters.

    i can see from the advanced example that you are passing one parameter (from index 1)

    but how to pass more than 1?

  • OK I think there is a bug where Previous versions of (New) Functions are still existing after being updated. This is why I am having difficulty seeing how to pass multiple parameters. Now there are multiple versions of changed functions with the same name.

    Not sure if this bug is covered by github.com/Scirra/Construct-3-bugs/issues/2851

    I cant raise a new bug right now as am at work with upload restrictions.

    EDIT

    ohh apparently I can upload to git hub from work :) (seems they dont block that site)

    one moment......

  • OK submitted bug report

    github.com/Scirra/Construct-3-bugs/issues/2867

  • re maps, I Ive got it now except how to pass multiple parameters.

    i can see from the advanced example that you are passing one parameter (from index 1)

    but how to pass more than 1?

    Just add them. It means "pass all parameters from index 1 to the end" - not only to pass 1 parameter.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • oh cool, I get you , nice...

    cheers

    edit

    tried it works real nice.

    it is awesome the way everything and anything now updates across functions when you change or add anything.

    very cool great new feature.

  • Ah I see, thank you for explaining!

  • To answer your question of when it might be used.

    For example, in my game there is a function called "TriggerAction"

    This function is called very often, it does everything from create sets of enemies to change the background to start and stop the game.

    Every time "TriggerAction" is called it looks up a string in an array table. The array table is one of many called "Level 1/2/3" etc and each is just a list of things to do to make a level.

    so it will be like Level 1 array

    "Set Background"

    "Create Player"

    "Create Enemies"

    and so on.

    the "TriggerAction" function will go through the array list one by one.

    each of these strings in the array is actually the name of another function.

    And when the "TriggerAction" function is triggered, it in turn, calls a Function with the name of the "string" it finds in the array table at that time.

    This is how levels get made in my game.

    This is maybe a simple way of using it but you can now see that the String to call can be made up from any number of combinations of other strings to form the name of the functions to be called.

    So one single function can run a set of events to determine what other function should be called from a list of functions based on the function map.

    ok im starting to confuse my self now so I will stop. just wanted to try to answer your original question.

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