Understanding Function Maps

0 favourites
  • 9 posts
  • As a C2 user I've been trying to learn more about C3's new features. Maybe someone could help me see the value in Function Maps?

    I checked out the Function Map tutorial included in C3, but that only made things more puzzling. It seemed like it took 3x more work to do something you can make with one function and some if statements.

    For example: here's a picture of the C3 Function Map tutorial done without function maps. It's much less work and much simpler — but I'm sure I'm missing something valuable about these maps.

  • In C2 it was possible to call functions by name. You could do things like Call Function choose("SpawnZombie","SpawnVampire"), or even Call Function "Spawn"&choose("Zombie","Vampire")

    In C3 it's not possible, you can only pick function name from the list. That's why function maps were added.

    Of course, in your example it's easier to just use a function parameter. But imagine you have several large functions with very different code and you need to call one of them dynamically by a string name.

    Having said that, I haven't used function maps myself, I find this concept too complex and cumbersome.. I still prefer to use a bunch of If-Then-Else blocks.

  • Funny around one week ago I finally said that's it today I'm gonna learn the New Function Maps because it's been too long on the waiting list to study and my c2 project uses Call Function by string everywhere, so I took the example from c3 main page called "Functions Maps" and I read it so many times the Tutorial until my brain fried, I couldn't make any sense of what I was reading and I gave up, luckily some good heart on Discord suggested to use Scripting for that.

    It's a shame because it was so useful and Fun and simple to call Functions by strings.

  • Here's a simpler function map example that hopefully is a stepping stone to the official example:

    dropbox.com/s/z7ukfyh1tmgkf1l/functionMap.c3p

    In the official version they add in two other steps:

    A parent function ("CallColor") that allows you to pass parameters to the function map.

    A "Default" function in the function map that will catch any calls that don't match with any functions in the map.

  • A use I've found for Function Maps is being able to call functions from within my JSON-based dialogue system. Basically you store a string in the JSON, then by mapping a function to that string, you can call the function later on.

    This explains the use case hopefully a little better.

  • Laura_D Good point! I just remembered that in my game Planet-O-Tron all button sprites have an instance variable, that contains function names. When any button is pressed, I call its function from that variable. So that's another way to use function maps.

  • Well, I see function maps as a form of polymorphism concept. But that's because I come from an object-oriented programming language background. So, for me it is a very interesting way to make your code more extendable, like, making your functions more reusable. I think it could also be useful to implement delegates/callbacks (or at least a resemblance of that).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey, thanks everyone. And thanks for the example mekonbekon — personally I think that should replace the one included in C3, the instructions and example were super clear!

    I see why the maps were created, but it still just seems to complicate the code (and the event sheet) more than it used to. Wouldn't this all be a lot simpler if you could just call a function by name/string?

    For an approachable dev platform like C3, it feels like something as fundamental as functions shouldn't be getting more complicated over time. Not that function maps shouldn't exist, as there's some super cool uses of them here like dialogue, but in addition to the basics like calling by string.

  • Having said that, I agree that for a starting user or for someone who doesn't know about coding may think function maps are too confusing and even overkill, demanding a lot more typing than using a bunch of if-elses. And for a small project it is true indeed.

    But, for a huge game with lots of levels, upgrades, skills, and so on, mapping functions to execute similar actions with different parameters will be a huge boost in your coding process and also with readability and maintenance (just like the JSON dialogue system Laura_D has pointed).

    So, what I really wanted to say is that function maps (along with the scripting feature) is a powerful tool that allows us to make bigger projects, and elevates Construct 3 level against other competitor game engines.

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