What you need is to use ‘After taking the cookie:’ since if the player types ‘Take x from y’, ‘Remove x from y’ etc. these are all ultimately, if the action successfully negotiates various rules about removing things, converted into a simple ‘Take x’. As mentioned above, you can see this conversion happening if you type ACTIONS when running the story then try out various ways of taking/removing the cookie…
The difficulty is that by the time you reach the ‘After’ stage of the action, the taking has already happened in the ‘Carry out’ stage, so the cookie is no longer in the pocket but is held by the player. Consequently conditions like ‘while the cookie is in the pocket’ will not apply in the ‘After’ stage.
Fortunately Inform retains a memory of the world state (and therefore where the cookie was) at the start of the turn, before the action began. So this works…
After taking the cookie when the cookie was in the pocket:
Another option is to use ‘the container in question’ which is set by Inform to any container that the action requires reaching inside:
After taking the cookie when the container in question is the pocket:
You could also avoid this difficulty by intervening at the Instead stage of the Take action, while the cookie is still in the pocket, and move the cookie to the player yourself, but it’s generally best to make use of the standard rules for the moving of things wherever possible, as there’s lots to think about in deciding whether or not this should be allowed. Using the After stage guarantees that all the standard checks and rules about taking something have been allowed to run and have succeeded.
A final option is to award points once all checks on the action have been carried out and passed, so it is guaranteed that the taking action will succeed and the Carry out taking rule will run, but it’s not actually happened yet:
Last check taking the cookie when the cookie is in the pocket:
decrease the score by 1 ;
Using ‘Last check…’ guarantees that this is the very last thing to happen before Taking is actually carried out, since the Check stage happens immediately before the ‘Carry out’ stage of the action.