I think your best bet is to replace the walking gani while the player is attacking, and then set it back to the walking gani when the player is done their attack.
I.e:
PHP Code:
function attack() {
replaceani("walk", "new_walking_ani");
this.scheduleevent(0.5, "FixWalkingAni", "");
}
function onFixWalkingAni() {
replaceani("walk", "proper_walking_ani");
}
Your walk check seems unnecessary.