Adding & Subtracting Variables

I tried to create a calorie meter : http://crisptalks.com/story_html5.html

Here are few problems that I am facing:

- The variable "cal" is increasing its value even if I am moving the item inside the hotspot. For ex: if the burger is inside hotspot and value of cal is 200 then if I am moving the burger inside the hotspot then again it is adding the value 200 to the variable "cal".

- I am not able to subtract the variable "cal" when I am dropping incorrect or bringing it back to its usual place.

3 Replies
Tracy Parish

I've been pondering this all night and I think I have it.  The variable CAL will adjust as you want it to if you do the math (+/-) based on the states of the food rather than where they are placed.

So for the burger and hotdog I have removed your two drop correct/incorrect states and instead added OnPlate OffPlate states.  When the burger is dropped on the hotspot, change the state to ONPLATE.  If the state of the burger is ONPLATE add 200.  When the burger is removed and dropped back to its original position then change its state to OFFPLATE.  If the state of the burger is OFFPLATE - 200.  

Now I then tried having the user just drag the burger off the plate and onto your lower rectangle, but it snapped to the middle of the rectangle.  So I added a transparent square behind the burger so that when the person takes the burger off and places it back where they found it, it appears to be back to "starting position".

But what if they don't put it back to its starting position.  2 options there (perhaps) make a semi-transparent shape of the burger and leave it as a shadow on the rectangle at the bottom so users feel compelled to put it back there.  Or Leave (as I did) the option that if the burger is dropped on the burger-spot or the bottom rectangle -200 happens.

I duplicated these steps for the hotdog as well and it seemed to all work.  One more thing I did was change the drag and drop options of the hotspot on the plate and turned off the "snap dropped items to drop target".  That looked more natural and the food was placed where ever the user left it on the plate.

Hope this helps you develop a solution.

Rachna Ghiya

Tracy, I am not able to figure out how can I make sure that food objects return to their respective positions when user drops them in the lower rectangle. In my case, they all returns to center of the rectangle (2 options there (perhaps) make a semi-transparent shape of the burger and leave it as a shadow on the rectangle at the bottom so users feel compelled to put it back there. - I did this but I am not sure how to make that food item follow a path). Your help will be appreciated.