How do I split animation name into two strings?

0 favourites
  • 4 posts
From the Asset Store
3 pixel charaters with over 8 animations each + animations with a gun
  • So, I have a card object that have a default animation as a back side of the card, and each card will have an element and a power. These elements and power are represented as an animation in the card object.

    The elements are fire, earth, water, air

    The power is a number from 1 t0 10

    so, the animation can be fire_1, fire_2, fire_3, all the way to fire_10. The same for other elements like water_7, earth_6, air_10, etc.

    The cards are not all created yet, since in the game they are still in the deck. The cards are created after the player (or enemy) draw the cards from the deck. I can set the correct animation to play so if the player draws 5 cards fire_1, earth_3, water_8, water_3, air_10, they all show the correct image.

    The problem starts when I want to assign the element and power to the card's instance variables (power and element has their own instance variable). At first, I imagined it'd be similar to JavaScript's split() function where I can split a string to several strings based on the separator. But I just realized I can't do this in Construct 3.

    I already look at the manual and the best thing I can find is search if a string has "fire", "earth", "water", or "air" in it, I can do this to get the element, but I can't get the power value.

    Can anyone help? Thanks.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The closest thing I found to what you're describing is tokenat() expression so for example for fire_1, tokenat("fire_1",0,"_") returns fire and tokenat("fire_1",1,"_") returns 1. The middle value is its position in the string and the final value is using the underscore as a separator.

  • That might be the solution! I'll try it out and see if it works.

  • yep, I used tokenAt and it works the way I want it.

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