Subtracts and sums, Liters simulation
Hi guys, i gotta a question about subtracts and sums, imagine have five containers each one with different capacities, so i got some with liquid and i have to spill the liquid inside others and i have to show how many liquid is inside in each one doing subtract and sum, my problem is that i don't know how to put a limit in subtract and sum, i have to make a formula and i am very bad in maths like i always say, if somebody have done something similar please let me know, thanks in advance.
Comments
I can't quite understand what you're trying to do. Can you explain a little more about what you mean by "limit"? If you can give a sample math problem that shows what you're trying to do (or even just write "I want to add the height of one container's liquid to the height of another but make sure the sum doesn't exceed 50..."), it will make it clearer.
If I had to guess about what you're trying to do, I'd go with the min() and max() functions. Have you worked with those in GameSalad?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Imagine you have 5 containers: the first one with 5 liter capacity, the 2nd one with 4 liters capacity, the 3rd with 3 liters cp, the 4th with 2 L Cp and the last one with 1 L cp.
So the first one is full with 5 liters of water the only 5 liters in the game the other are empty, the game is about pour the water in the others containers:
e.g.: The 5 L cp container pours its water into the 3 L cp container, so the 3 L cp containers is full now and the 5 L cp container has 2 liters of water now.
So the math is case (from 5 to 3) something like this i think, first for each one container i got 2 numbers (index attributes), the content (water) and the capacity, i.e.: 5 L cont and 5 L cap and 3 L cont and 3 L cap.
Where i think that 5 L cont= 5 and 5 L cap=0 (because it's full) and 3 L cont=0 and 3 L cap=3 (Because it's empty)
So here is where i get stuck:
5 L cont= 5 L cont-3 L cap (2 liters)
3 L cont= ?
5 L cap= ?
3 L cap= ?
I think it is a way to do this, but i can't do it all, if you know a way with max and min or if you figure it out how to do it with way let me know please, the solution has to work universally with all the cases e.g.: (from 3 to 1), (from 5 to 2) etc.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
5Lcont=5Lcont-3Lcap ... but only if 3L container is empty; otherwise, it's 5Lcont=5Lcont-(3Lcap-3Lcont)
3Lcont=3Lcont+(5Lcont-3Lcap)
5Lcap=5Lcap+(5Lcont-3Lcap)
3Lcap=3Lcap-(5Lcont-3Lcap)
Since you're re-using a difference formula repeatedly, you could do a Change Attribute game.transferAmount to game.5Lcont-game.3Lcap and just use game.transferAmount in place of each (5Lcont-3Lcap) above, but that's assuming these equations all work!
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
The selection mode is tapping first the "source" container and then "destination" container, only can be selected as "source" the containers which contains water and only can be selected as "destination" the containers who aren't full, the water amount of the water can't be selected, it will only fill the container till its top, so it will subtract the current capacity of the destination to the source and if the content is bigger than the capacity it's going to remains water in the source. It's a imitation of real pouring and filling. Thanks for your time and help my friend.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
I solved it, i had to add another two index attributes, "Real Capacity" (RCap) and "Beginning Content" (BCont) and Capacity is called now "Current Capacity" (CCap)so it is the equation:
e.g.: From 5 to 3:
BCont = 5LCont
5L Cont = 5L Cont-3L CCap
3L Cont = 3L Cont+(BCont-5L Cont)
3L CCap = 3L RCap-3L Cont
5L CCap= 5L RCap-5L Cont
BCont = 0
Thanks for your help! take care.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User