Are Any of You Good Enough at Math to Help me?

Started by jkid101094, January 01, 2014, 08:32:00 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jkid101094

Quote from: GoWSo I need help from you people that are much smarter than I.

What I want to do for a thing I'm working on is make it so that every 25G you spend at a store earns you one store credit. When you have enough saved up you will be awarded by the store's owner.

However, right off the bat there isn't a way to check if a number is divisible by 25 (I can divide numbers but I'm horrible with division) so I've wrote a roundabout 'algorithm'.

There are seven variables in this and they are as follows;

Mall - G Spent
Mall - PP Earned
Mall - Pre Event G
Mall - Post Event G
Mall - G Hold
Mall - PP Hold
Mall - Prev G Hold

'G Spent' and 'PP Earned' are just that. How much money you've spent in total and how much Store Credit (PP) you've earned in total.

"Pre Event G" records how much G you have going into a shop screen and "Post Event G" records how much you have leaving it. The game then subtracts the later from the former to find how much you spent and records it to "G Spent".

You have an item called a "Points Card". When you check it displays the number of points you have and the money you've spent. It also decides how many points you've earned since the last time you've used it and gives them to you.

Roughly converted from the RPGMVXAce event format into something similar to an actual algorithm the process goes something like this:

Mall - G Spent = A
Mall - PP Earned = B
Mall - Pre Event G = C
Mall - Post Event G = D
Mall - G Hold = E
Mall - PP Hold =F
Mall - Prev G Hold = G

E = (A+1)
Loop Start
E > G?
E - 25
E > G?
F + 1
Loop
-------------------
Then regardless of how many times that check was done it'll display the value of 'PP Hold' to the player, telling them they've earned that many points as well as adding that value to 'PP Earned'.

It then proceeds to wipe all of the 'Hold' variables except for 'Prev G Hold' which is overwritten by the value of 'G Spent' to check whether or not your G has increased since your last check.

Let me give an example with values plugged in;

A = 75
B = 0
E = 0
F = 0
G = 0

[E = (A+1)] = 76
Loop Start
E > G? (76 > 0?) YES
(E - 25) = 50
E > G? (51 > 0?) YES
F + 1
E > G? (76 > 0?) YES
(E - 25) = 51
E > G? (51 > 0?) YES
F + 1
Loop
Loop Start
E > G? (51 > 0?) YES
(E - 25) = 26
E > G? (6 > 0?) YES
F + 1
Loop
Loop Start
E > G? (26 > 0?) YES
(E - 25) = 1
E > G? (1 > 0?) YES
F + 1
Loop
Loop Start
E > G? (1 > 0?) YES
(E - 25) = -24
E > G? (-24 > 0?) NO
---------------------------------------------
The algorithm would then add 3 to 'PP Earned" wipe the 'Hold' variables to 0 and then set 'Prev G Hold' to 75.

Now here is where the problem lies. Let me try that again with a different input.

A = 75
B = 2
E = 0
F = 0
G = 55

Running the algorithm would cause a glitch in this case (as it did for me).

[E = (A+1)] = 76
Loop Start
E > G? (76 > 55?) YES
(E - 25) = 51
E > G? (51 > 55?) NO
--------------------------------------------

Clearly in this scenario I have spent enough to earn three points yet since the check failed I can't earn the 3rd one. What is worse is that every check you do that would give a remainder of anything less than 25 (5 in the last one) it breaks the check.

I'm somewhat sure how to fix the problem now that I've explained it in full detail, but do you guys have any ideas? I know some of you are pretty good at math or at least better than I am.


Quote from: DracoDraco:  Saber was my bitch LONG before you heard about her.  I introduced you to FSN, loser.  D<
Oh, and still...
ILU JKIDDD

Says you. She likes me more. D<
And ILU2. o3o
IaFNSW.


jkid101094



Quote from: DracoDraco:  Saber was my bitch LONG before you heard about her.  I introduced you to FSN, loser.  D<
Oh, and still...
ILU JKIDDD

Says you. She likes me more. D<
And ILU2. o3o
IaFNSW.