1. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

Math class?

Discussion in 'Modding Help' started by JaytleBee, Apr 29, 2015.

  1. JaytleBee

    JaytleBee Ballista Bolt Thrower
    1. [Server] Sandbox Reborn

    Messages:
    117
    Is there any way to use logarithms in kag's engine? Importing scriptmath freezes the blob.
     
  2. Verrazano

    Verrazano Flat Chested Haggy Old Souless Witchy Witch Witch THD Team Global Moderator Forum Moderator Tester
    1. Practitioners of War Extreme Revolution - POWER

    Messages:
    477
    Importing scriptmath freezes the blob because, a) you include in angelscript not import and b) there is no scriptmath file available unless you made it. These would cause compile errors and your blob would not work. Just use the math functions. You can find a list of them in Manual/interface/Functions.txt. They are contained in the global namespace Maths.

    [​IMG]

    --
    Edit: I assume you might have seen that there was a scriptmath file from the application developers manual on the angelscript website. However that file is for the actual engine code and is used to bind most math.h functions for use in scripts.
     
  3. Asu

    Asu THD Team THD Team Forum Moderator

    Messages:
    1,580
    Also, check in the console for the script errors. You're never gonna make a mod properly if you only know your code fails (but not where).
     
  4. JaytleBee

    JaytleBee Ballista Bolt Thrower
    1. [Server] Sandbox Reborn

    Messages:
    117
    Thank you so much!

    I do, but there where none. It just froze the blob.
    --- Double Post Merged, Apr 30, 2015, Original Post Date: Apr 30, 2015 ---
    Okay, Math.Log has a base of e. Is there any way to use a Logarithm with a base of ten?
     
  5. Asu

    Asu THD Team THD Team Forum Moderator

    Messages:
    1,580
    Try doing /rcon rebuild, you'd see the errors.
     
  6. Fernegulus

    Fernegulus Bison Rider

    Messages:
    400
    I don't think so, you need to use the formula and be thrice as heavyweight :/
     
  7. Verrazano

    Verrazano Flat Chested Haggy Old Souless Witchy Witch Witch THD Team Global Moderator Forum Moderator Tester
    1. Practitioners of War Extreme Revolution - POWER

    Messages:
    477
    [​IMG]

    i.e if you wanted something to use log base 10. You can do this:

    float ret = Maths::Log(x)/Maths::Log(10);

    This method is pretty fast. Regular TI calculators use this method commonly to calculate arbitrary bases using e.
     
    makmoud98 likes this.
  8. JaytleBee

    JaytleBee Ballista Bolt Thrower
    1. [Server] Sandbox Reborn

    Messages:
    117
    Thank you so much!
     
  9. Fernegulus

    Fernegulus Bison Rider

    Messages:
    400
    Yes I know, just getting logs of things is generally pretty heavy.
    Depends on whether you want to do it 10 times a second or once every few minutes...
     
  10. JaytleBee

    JaytleBee Ballista Bolt Thrower
    1. [Server] Sandbox Reborn

    Messages:
    117
    Is there any better way of getting single digits of an integer (except casting to string)?
    --- Double Post Merged, Apr 30, 2015, Original Post Date: Apr 30, 2015 ---
    Sorry, my train of thought was probably not obvious there. I currently use logarithms to get the number of digits an int has.
     
  11. Verrazano

    Verrazano Flat Chested Haggy Old Souless Witchy Witch Witch THD Team Global Moderator Forum Moderator Tester
    1. Practitioners of War Extreme Revolution - POWER

    Messages:
    477
    Log isn't that slow. You can safely do log operation a 100-1000 times a frame if you wanted. I think you misunderstand the speed at which computers do math operations. The heaviest weight things for computers are moving/fetching memory and rendering. Of course it has overhead and cpu time, but it's really not that expensive.

    Here is a handy dandy chart that shows the time complexity of computing log using different methods: http://en.wikipedia.org/wiki/Computational_complexity_of_mathematical_operations#Elementary_functions
    You can use the modulo operator and divide.

    for (int digitPlace = 0; num > 0; digitPlace++) {
    int currentDigitVal = num%10;
    num /= 10;
    }

    This works assuming you want to iterate through all the digits and num is an int.
     
    Last edited: Apr 30, 2015
    Asu likes this.
  12. JaytleBee

    JaytleBee Ballista Bolt Thrower
    1. [Server] Sandbox Reborn

    Messages:
    117
    Yeah, that's what I'm doing right now. I think my phrasing was pretty bad there. Anyways, thanks for all the help.