Make different animations with the same button

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Prisma

Hello, good afternoon, my English is not very good, here’s the problem, I have an introduction to the game that tells a story, it’s like a canvas that moves forward and below the text comes out as the illustrations are shown, every time the text ends the “next” button appears and the animation has to show the next frame, there the problem, how is it a single button and has its action is to show animation1 and I even have animation7 , what I want is that every time you click on the button add a number to a variable, the next time it checks what number of click (variable) you are and according to that number change the animation This is my first project so I don’t understand much. thanks

:bust_in_silhouette: Reply From: DaddyMonster

Something like this would do the trick. You need to add a signal from your button to where this script is. It will run through playing the animations every time you click:

var anim_selected = 0 #anim playing
onready var anim = get_node("path to anim node") #your anim node
onready var anims = anim.get_animation_list() #an array with your anims

_on_button_pressed():[anim_selected % anims.size()]) #google "modulus" for "%"
    anim_selected += 1 # go to the next anim