Arithmetics Question

Level 12
Joined
May 4, 2008
Messages
1,111
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
 
Level 11
Joined
Aug 1, 2009
Messages
963
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:

Dr Super Good

Spell Reviewer
Level 58
Joined
Jan 18, 2005
Messages
26,501
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.
 

Dr Super Good

Spell Reviewer
Level 58
Joined
Jan 18, 2005
Messages
26,501
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).
 
Level 12
Joined
May 4, 2008
Messages
1,111
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
 
Level 23
Joined
Nov 29, 2006
Messages
2,483
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.
 
Level 12
Joined
May 4, 2008
Messages
1,111
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
 

Dr Super Good

Spell Reviewer
Level 58
Joined
Jan 18, 2005
Messages
26,501
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.
 
Top