Transition animations while walking / keeping key pressed

Hello everybody

I am new to Disfold and having problems with animation.

I have a player that has animation for walk, idle and attack (for 4 directions)
Example:
Walk left is keybinding is ‘A’ and attack is space-key. If I hold ‘A’ my player starts walking and plays the correct animation. If I release ‘A’ the players stop and the idle_left-Animation is played.

So far, so good.

But if I walk (e.g. hold the ‘A’ key pressed) and then hit space-key once, the attack animation will not play instantly but after I release the ‘A’-key.

What I want:
While the player is walking, if I hit space-key, the attack-animation should play and the player should continue walking animation after the attack animation finished.

Can somebody help me with this, please?

Here some code snippit:

local function anim(self)
	
	local f = "down"
	if self.facing.y > 0 then
		f = "up"
	elseif self.facing.x > 0 then
		f = "right"
	elseif self.facing.x < 0 then
		f = "left"
	end

	local a = hash("idle_"..f)
	local moving = vmath.length_sqr(self.velocity) > 0.01
	if moving then
		a = hash("walk_"..f)
	elseif self.attacking then
		a = hash("attack_"..f)
	end

	if a ~= self.anim then
		self.anim = a
		sprite.play_flipbook("#sprite", self.anim)
	end
	
end
function update(self, dt)                           
	
	if vmath.length_sqr(self.input) > 1 then
		self.input = vmath.normalize(self.input)
	end

	if vmath.length_sqr(self.input) > 0 then
		self.facing = self.input
	end

	anim(self)
	
	local p = go.get_position()
	local newp = p + self.input * self.speed * dt
	go.set_position(newp)

	
	self.velocity = p - self.pp		
	self.pp = p
	self.input = vmath.vector3()
	self.correction = vmath.vector3()
end
function on_input(self, action_id, action)   

	if vmath.length(self.input) > 0 then
		self.moving = true                          
		self.dir = vmath.normalize(self.input)     
	end

	
	if action_id == hash("up") then
		self.input.y = 1                           
	elseif action_id == hash("down") then
		self.input.y = -1
	elseif action_id == hash("left") then
		self.input.x = -1
	elseif action_id == hash("right") then
		self.input.x = 1
	elseif action_id == hash("attack") then
		self.attacking = true
	elseif action_id == hash("shoot") and action.pressed then
		self.fireball = true
	elseif action_id == hash("attack") and action.release then
		self.attacking = false
		
	end

	
	if vmath.length(self.input) > 0 then
		self.moving = true                          
		self.dir = vmath.normalize(self.input)     
	end
end