Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics

You will be able to do this with variables.
In your  dialogue you could have a conditional node on the sprite that want's to trade the ball for the cookie and have 3 conditions that would look something like this: (b for ball - c for cookie. Makes sense right? Though you can use any letters you want)


Now in order to get the cookie in the first place you would need pick up a cookie. So in the dialogue for the cookie you should add {c=c+1} to the end of it so the player actually has a cookie to trade. 

Here's a copy of the game I made for this explanations. Feel free to have a dig.
Here's an in depth tutorial on bitsy variables

Hope this helps! 

Is this up to date?