[SOLVED] Equation Randomly Stops Working
JoeB
Member Posts: 160
So I have an equation : Change attribute: self.Happiness Percentage to self.A/self.B
Sometimes it works, sometimes it doesn't, it usually works after I restart game salad or hit the 'reset' button on the game salad viewer a lot. Anyone?
Comments
There is a whole world of attributes and rules and behaviours going on in your game that no one can see, for all we know the issue is with the way the timer, which self.B is wrapped in, stops adding 10 to self.B when self.A is larger than 30, but it should only stop adding 10 when self.A is larger than 60 . . . but how would anyone know as all you have said is 'it doesn't work' and that could mean anything - it returns an invalid expression error, it crashes GameSalad, it returns the wrong value, it doesn't track self.A correctly, or self.B gets taken away instead of added, or self.Happiness Percentage is always 0 regardless of the values of self.A and self.B . . . . and thousands of others possibilities !
Think of it like this, I have a sum, I am adding two numbers together, but it doesn't work, can you offer me any advice ?
Thanks for the reply, so it goes like this:
The equation is controlled by a timer and every other computation within the timer works perfectly as far as I can tell. This particular equation that doesn't work is supposed to set a percentage (the percentage of happy people in a village, it's the game I'm working on.) So it's Happiness = self.happy people / self.population * 100. When I try this, the real number doesn't change - I use a display text command in an actor to see the self.att Happiness and it doesn't change.
Now sometimes the equation works, sometimes it doesn't. It works for a while if I reenter the equation but then it usually doesn't work again, which is weird because I haven't encountered that before. To test it out, I tried swapping out the division in the equation with multiplication, so self.happy people * self.population * 100 and the equation 'works' in that the number in the display text actor changes.
I've already made and released four games in game salad and this is the first time I've encountered this, I just find it weird.
I tried everything but it just seems to malfunction sporadically, I even put it in its own timer.
Anyway, is there a way in game salad to find the ratio of something without dividing it? I know I can cross multiply on paper but how do I do it in game salad? It would be something like self.happy people/ self.population = self.happiness ratio/100
I would really really appreciate some help as I've been trying to solve this for two days now
My guess is there's something funky about the way you have your rules set up. I know that's really vague but it's the best I can do without seeing your actual rules. The math functions in GameSalad are precise and probably the things I trust most about the software. So if it works sometimes and doesn't other times, there's something else going on. Feel free to post a download link to your project (please .zip it first) and @Socks or I can take a look.
To answer your other question, there is no built-in ratio function but you can build very complex mathematical functions in the expression editor.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Thank you Socks and Tatiang, I reexamined my rules and you were right, there were 5 computations before that equation which executes every 1 second. My 'ratio equation' was using a variable that hadn't been computed yet which messed up the results.
Thanks again