PaulS:
but how to make the action perform one time only when the state doesn't change?
This doesn't make sense. When would you perform this action if the state doesn't change?
In your case, there is a state change, too open, when the lid is opened, and a state change, to closed, when the lid is closed.
Play the music when the state changes to open. Do nothing when the state changes to closed.
Sorry for my bad description.
What I mean is, I hope that when the box open(the state change), and the the music play one time only(run the action one time only), when the box is still open.
Now the code will make the box
Box open-->play music(keep playing until I close the box)--->Box then close--->box open---play music(keep playing until I close the box)
The whole thing i want to make is sth like
Box open-->play music(one time )-->Box then close--->box open--->play music(one time)
is it possible to achieve such a function?