# Arithmetics Question

#### kevv2

Level 12
Hello i just started a RPG map, and decided to do a somewhat good replica of FFVII's Level-up system, i got most of the coding down for it except one thing that stops me from going forward...

the EXP curve which requires a Real and not an Interger (and i still cant believe we dont have Arith.Real lol) the curve is... [MOD * ((LVL-1) ^ 2) / 10] MOD being 92.5 how would i write that down

(dont tell me write each EXP need in a vairable, im trying to avoid that, too much wasted space )

thank you

#### mrzwach

Level 11
You just need to use functions inside functions.

IE:
Code:
``````Set Variable
Variable: xp
Value: Arithmetic (Real)
Value 1: 9.25
Operator: *
Value 2: Power (Real)
Value: Convert Integer To Real
Value: Arithmetic (Integer)
Value 1: level
Operator: -
Value 2: 1
Power: 2.0``````
Given that xp is a fixed variable and level is an integer variable.

Also use the Galaxy Editor help zone next time.

Last edited:

#### kevv2

Level 12
i dont have Arithmetic(Real)

nvm im just stupid as hell XD

Last edited:

#### Dr Super Good

Spell Reviewer
Level 58
Why would nested functions be needed for something that does not invlolve itteration...

Additionally nested functions are very dangerous as they can cause a stack overflow error and crash the execution thread.

I would just write what you wrote down there...
[MOD * ((LVL-1) ^ 2) / 10]
As a single line of code matching simlar form to that but logically using galaxy statments.

You can convert integers to fixed and fixed to integers at any time.
native fixed IntToFixed (int x);
native int FixedToInt (fixed x);

You will need also...
native fixed Pow (fixed x, fixed power);
I would love to help you and give you the line for it but I am not too sure it would behave as you want (no information where to convert in it).

Incase you do not know, fixed is SC2's type for real numbers (and from its sound it is not the same as WC3 used floats I believe).
int is SC2's type for integer, it behaves exactly like WC3's in that they are both 32 bit signed with two's compliment.

#### Eccho

Level 23
@ DSG
Fixed values have the min and max value -2^19 and 2^19, but I don't recall what it was in wc3.

#### Dr Super Good

Spell Reviewer
Level 58
WC3 utalizes floating points, which mean the range was huge (easilly passed the millions) but the precision of the number meant that it was impossible to incriment large numbers by 1 (as the inaccuracy was greater than 1 unit at huge values).

SC2 uses fixed point. These have a much smaller range unlike floats but instead have linear distribution of values accross the range whereas floats have an inaccuracy based on the largest units. Additionally fixed point values are computed using normal integer instructions unlike floating points which require special floating point instructions (which are well known to be very time consuming instructions).

For his formula I would advise he try and cut out fixed values alltogether and directly use integers (as they will support the sizes he is after).

#### kevv2

Level 12
when i use my function used exactly the same i come off with a 60K difference in the 2 milions~ minor difference but a difference none the less, could it be a fail in the calculations of higher levels going slightly off mark and int he end being way off the mark

#### kevv2

Level 12
the name of the operation IS "Power" why would they call it stat if it wasnt

#### Eccho

Level 23
I am just saying that b^2 do is not equal to b squared (b*b) in programming, since that is the operator for xor.

Edit: maybe that is how they call it in GUI then. Yeha nevermind

#### Mooglefrooglian

Level 9
Several languages use ^ for exponentiation, and I use it anyways if I'm talking about math. It's also used by LaTeX when writing superscripts.

#### Eccho

Level 23
Several languages do not use ^for exponentiantion as well, and yes, for math it is used all the time.

But no, in pure galaxy scripting ^ does mean xor. In GUI it seems to be exponentiation, mainly because Blizzard decided to have it that way. But go figure why I myself got confused.

#### kevv2

Level 12
cuz GUI is user-friendly and Galaxy is a script language mebeh? XD User-friendly will always use terms that people understand

#### Eccho

Level 23
For does who does not know scripting, sure:>

#### kevv2

Level 12
i know scripting but i prefer GUI... as long as it doesnt give me headaches like writing out a math formula using Arithmetics in arithmetics in arithmetics in arithmetics and u forget which runs first! XD

#### Mooglefrooglian

Level 9
Just use a custom script and save yourself the time and pain.

#### Dr Super Good

Spell Reviewer
Level 58
Brackets always run first, followed by powers and logs (these are functions in SC2 so their insides are subject to the bracket layer), followed by multiplication and division then followed by addition and subtraction. If 2 of them at the same level are present, they are run from left to right order. If 1 caclualtion requires another to be computed ( bracket * bracket ) the dependants will be computed first.

If you lack he confidence to use the above, you can just wrap brackets around every 2 pairs so they execute in the order you want them to.

Replies
13
Views
5K
Replies
0
Views
438
Replies
12
Views
1K
Replies
12
Views
4K
Replies
11
Views
866