How do I get all animation names for a Sprite object using code?

1 favourites
  • 3 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • I have a Sprite object called "Weapons" with many animations named things like "Pistol", "Revolver", etc. How do I get the names of every "Weapon" object animation using an event sheet script or script file?

    Currently, I'm hard-coding the animation names into an array, but I'd like to not need to update the array whenever I add new animations. Here's an example:

    // This is a function block inside an event sheet called "GetRandomWeaponName".
    // It returns a random "Weapon" animation name that isn't the name of the currently wielded weapon.
    
    const weaponWielder = runtime.objects.WeaponWielder.getFirstPickedInstance();
    const currentWeaponName = weaponWielder.instVars.WeaponName;
    
    // This is the relevant part where I hard-code
    // all of the "Weapon" animation names.
    const otherWeaponNames = [
     "Pistol",
     "Revolver",
     "Shotgun",
     // All other names...
    ].filter(name => name !== currentWeaponName);
    
    const randomIndex = Math.floor(Math.random() * otherWeaponNames.length);
    runtime.setReturnValue(otherWeaponNames[randomIndex]);
    
    
  • This is currently not available in the API. You can vote for this idea:

    construct3-21h2.ideas.aha.io/ideas/C321H2-I-319

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for the info. I'll vote for this suggestion.

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