Can you call functions from String Instance Variables on a sprite?

0 favourites
  • 5 posts
From the Asset Store
Color Variable
$4.50 USD
10% off
Easily store, modify, read and manipulate colors with Color Variables!
  • I'm working on a turn based battle system, wondering if something like this is possible;

    I'd like to have, say, 5 string instance variables per enemy called 'Attack Slot 1' through 'Attack Slot 5'.

    The slots/string variables would each contain strings of different attack names, which in turn would be paired to corresponding functions with those names that would then trigger.

    When it's an enemy's turn to attack, a random number (1 - 5) generates and calls whatever function's name appears in that specific enemy's corresponding attack slot.

    For example;

    Enemy A may have the 'Punch' function listed in it's Attack Slot 1, while enemy B may have 'Kick' listed under it's attack slot 1. These would always be different depending on the type of enemy that is attacking, so I'm trying to develop universal attack calling logic that works regardless of the type of enemy via family instance variables.

    I'm digging into mapping functions and 'map function to string' but I'm getting confused as to how I could actually make that reference the string name in the enemy sprite's instance variables. Maybe I should instead be looking at arrays?

    I've attached a screengrab of how I'm trying to attempt solving this so far.

    Any help is appreciated, thanks gang.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • on start of layout you map all attack strings to their respective functions then you can call the function using enemy.variable as the string. Check out the manual as it has an example project.

  • Awesome, thank you for pointing me in the right direction lionz.

  • Functions map is the intended way to do this, but I find it difficult to use.

    Another option is call the function using scripting. Copy the function name into a local variable, then execute this script:


  • Thanks dop, I'll give that a whirl too. I found the example project for function mapping, but I do find it a bit confusing to figure out, not gonna lie!

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