Non-threaded

Forums » Advanced Editor Forum » Read Thread

Get help from the experts on variables, scripts, items, and other scary things.

Adding variables together?

8 years ago

I want to add variables together on page and then divide them so I can create an average of the variables to show the player on screen. How would I achieve that?

I realize I can show variables numbers on page by using %% but I don't know how to add or divide them against each other.

Adding variables together?

8 years ago

Script. You'll preferably need a third variable to store the mathematical result, and it has to be in a link script, or the number will display incorrectly.

%VAR3 := (%VAR1 + %VAR2) / 2

Adding variables together?

8 years ago

Okay, thanks! I had another question though.

What if I want to show the percentage of how close someone got to a particular result?

Like for instance, let's say there's a page A and page B. There's also variable X, Y, and Z.

To get to page A: X must be 6, Y must be 4, and Z must be 5.

To get to page B: X must be 3, Y must be 9, and Z must be 3.

Now, at the end of the game let's say the player got 5 for all variables. They can't get either option because they don't have the right set of numbers.
But I want to give them what they got closest to, so I say "if they got numbers between 4 and 6 for all three variables, then they got to page A". This works cause now they'll get page A but not page B.

However, let's say there's a page C and to get to this page: X must be 5, Y must be 5, and Z must be 6. Now they'll be given both links. For the purposes of my game that's okay, they can both links so long as they can end up somewhere, but I still want to show them what they got closest to.

So, I want to show them they were closer to C then A. Like, "you were 99% a match for C" and "you were 95% a match for A".

Can I accomplish that? Is that do-able?

Adding variables together?

8 years ago

Percentage proximity... well, it's a bit of a doozy, but you still can do it this way (where both 3/4 and 5/4 are counted as 75%; you can test it out here). You'll also need variables for the percentage results, like %APROXIM, %BPROXIM, and %CPROXIM:

The basic code is "IF %A > %B THEN %C := %C + 100 * (2 * %B - %A) / %B ELSE %C := %C + 100 * %A / %B", where %A is the current value, %B is the required value, and %C is the percentage, but it needs to be repeated thrice and averaged for X, Y, and Z, and also done for each page, so for pages A, B, and C, it would look like this:

## PAGE A ##
IF %X > 6 THEN %APROXIM := %APROXIM + 100 * (12 - %X) / 6
ELSE %APROXIM := %APROXIM + 100 * %X / 6
IF %Y > 4 THEN %APROXIM := %APROXIM + 100 * (8 - %Y) / 4
ELSE %APROXIM := %APROXIM + 100 * %Y / 4
IF %Z > 5 THEN %APROXIM := %APROXIM + 100 * (10 - %Z) / 5
ELSE %APROXIM := %APROXIM + 100 * %Z / 5
%APROXIM := %APROXIM / 3

## PAGE B ##
IF %X > 3 THEN %BPROXIM := %BPROXIM + 100 * (6 - %X) / 3
ELSE %BPROXIM := %BPROXIM + 100 * %X / 3
IF %Y > 9 THEN %BPROXIM := %BPROXIM + 100 * (18 - %Y) / 9
ELSE %BPROXIM := %BPROXIM + 100 * %Y / 9
IF %Z > 3 THEN %BPROXIM := %BPROXIM + 100 * (6 - %Z) / 3
ELSE %BPROXIM := %BPROXIM + 100 * %Z / 3
%BPROXIM := %BPROXIM / 3

## PAGE C ##
IF %X > 5 THEN %CPROXIM := %CPROXIM + 100 * (10 - %X) / 5
ELSE %CPROXIM := %CPROXIM + 100 * %X / 5
IF %Y > 5 THEN %CPROXIM := %CPROXIM + 100 * (10 - %Y) / 5
ELSE %CPROXIM := %CPROXIM + 100 * %Y / 5
IF %Z > 6 THEN %CPROXIM := %CPROXIM + 100 * (12 - %Z) / 6
ELSE %CPROXIM := %CPROXIM + 100 * %Z / 6
%CPROXIM := %CPROXIM / 3