• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Need to split up numbers

Status
Not open for further replies.
Level 13
Joined
Mar 24, 2010
Messages
950
no that wont help that just lets me use decimal point values

I think the best way to do this would be string manipulation but not sure of the most efficient way this should be done. i dont like string manipulation much.. lol
 
Level 13
Joined
Mar 24, 2010
Messages
950
I pretty much got it done here as a test

  • test
    • Events
      • Player - Player 1 (Red) types a chat message containing -num as A substring
    • Conditions
    • Actions
      • Set Temp_Integer = (Integer((Substring((Entered chat string), 6, (Length of (Entered chat string))))))
      • Set Temp_String = (String(Temp_Integer))
      • Game - Display to (All players) for 4.00 seconds the text: Temp_String
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Temp_Integer Greater than 999
        • Then - Actions
          • For each (Integer A) from 1 to (Length of Temp_String), do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Integer A) mod 4) Equal to 0
                • Then - Actions
                  • -------- Insert Comma --------
                  • Set Temp_String = ((Substring(Temp_String, 1, ((Integer A) - 1))) + (, + (Substring(Temp_String, ((Integer A) + 0), (Length of Temp_String)))))
                • Else - Actions
        • Else - Actions
      • Game - Display to (All players) for 4.00 seconds the text: Temp_String
but when i type in 1234567
it outputs 123,4567 it should be 1,234,567 :/
 
Last edited:
Level 5
Joined
Dec 4, 2006
Messages
110
Here's my fixed script in JASS.

JASS:
function AddCommas takes integer whichInteger returns string
    local string s = ""
    local integer sign = 1
    local integer i = 0
    local integer j = 0
    local integer k = 0

    // Store the sign and if negative, make whichInteger positive so we don't have to deal with that nasty negative dividend stuff
    if (whichInteger < 0) then
        set sign = -1
        set whichInteger = -whichInteger
    endif

    // Check if there needs to be commas
    if (whichInteger < 1000) then
        return I2S(whichInteger * sign) // No commas to add
    endif

    // Add the commas using nifty modulo and some maths
    loop
        exitwhen whichInteger < 1000
        // Find the exponent as a truncated integer for some place counting
        set i = R2I(Log(I2R(whichInteger)))
        // Exponentiate 10 to the exponent we found earlier
        set k = R2I(Pow(10, i))
        // Use k to get the leading digit
        set j = whichInteger / k
        set s = s + I2S(j)
        // If the exponent is divisible by 3 then it warrants a comma
        if ( i - (i / 3) * 3 == 0 ) then
            set s = s + ","
        endif
        // Subtract the leading digit
        set whichInteger = whichInteger - (j * k)
    endloop

    // Add the remaining three digits
    set s = s + I2S(whichInteger)

    // Add the negative sign if the original was negative
    if (sign == -1) then
        set s = "-" + s
    endif

    return s
endfunction

But, right now it's broken if you have zeroes. Which is a big problem.

I see no way of fixing that short of going into string conversion.

I could fix it... Just give me a moment.

It uses this logarithm script by the way:

JASS:
//==============================================================================
//  Logarithm script by X - Version 1.0 - December 12, 2009
//==============================================================================
//
//  about:
//      - compute natural logarithm of a real.
//      - compute logarithm to the base b of a real.
//       
//  Usage:
//      - Ln(x)   to compute the natural logarithm of the real x
//      - LogB(x, b) to compute the logarithm to the base b of the real x
//      - LogBV2(x, b) to compute the logarithm to the base b of the real x with another method, see Notes
//      - Logarithm_e to acces the value of the constant e
//
//  Notes:
//      - Ln(x) is exactly the same as LogB(x,Logarithm_e)
//      - LogBV2(x,b) is Ln(x)/Ln(b)  , make your own tests to compare it to LogB(x,b)
//      
//      - you can find the algorithm used at this address :
//              [url]http://en.literateprograms.org/Logarithm_Function_%28Python%29[/url]
//              it is the same as the basic one explained by Donald E. Knuth in his book
//
//      - reals in jass are not very precise, something like 9 total digits. Be happy if it works
//
//  Requirements:
//      - JassHelper.
//
//  Installation:
//      - Create a new trigger called Logarithm.
//      - Convert it to custom text and replace all the code with this code.
//
//  Special Thanks:
//      - Ammorth: for is LinkedList information layout 
//
//==============================================================================

library Logarithm

   globals
       public constant real e = 2.718282  //e=2.71828182845904523536
       private constant real EPSILON = 0.0000001 // dont use lower values, jass reals sucks
   endglobals
    
    function Ln takes real x returns real
        local real decimal = 0.0
        local real partial = 0.5
        local integer i = 0
        if x <= 0 then
            return 0
        endif
        loop
            exitwhen x >= 1
            set i = i - 1
            set x = x * e
        endloop
        loop
            exitwhen x < e
            set i = i + 1
            set x = x / e
        endloop
        set x = Pow(x,2)  // maybe power is more accurate than x*x -_-'
        loop
            exitwhen partial <= EPSILON
            if x >= e then
                set decimal = decimal + partial
                set x = x / e
            endif
            set partial = partial * 0.5
            set x = Pow(x,2)
        endloop
        return i + decimal
    endfunction

    function LogBV2 takes real x, real base returns real
            return Ln(x)/Ln(base) 
    endfunction
    function LogB takes real x, real base returns real
        local real decimal = 0.0
        local real partial = 0.5
        local integer i = 0
        if x <= 0 or base <=0 then
            return 0
        endif
        loop
            exitwhen x >= 1
            set i = i - 1
            set x = x * base
        endloop
        loop
            exitwhen x < base
            set i = i + 1
            set x = x / base
        endloop
        set x = Pow(x,2)
        loop
            exitwhen partial <= EPSILON
            if x >= base then
                set decimal = decimal + partial
                set x = x / base
            endif
            set partial = partial * 0.5
            set x = Pow(x,2)
        endloop
        return i + decimal
    endfunction
   
    function Log takes real x returns real
        return LogB(x, 10)
    endfunction
endlibrary
//==============================================================================
//  End of Logarithm script
//==============================================================================
 
Level 5
Joined
Dec 4, 2006
Messages
110
Your code won't work. In order to make it work right, it'll get as long (probably longer) than what mine will be.

It'll also be less efficient.

At any rate, I'm thinking I'm almost done.

I've finished it.

I've made it work entirely off strings because there's just no way to do it otherwise.

JASS:
function AddCommas takes integer whichInteger returns string
    local integer sign = 1
    local string s = ""
    local string t = ""
    local integer i = 0
    local boolean b = false

    // Store the sign and if negative, make whichInteger positive so we don't have to deal with that nasty negative dividend stuff
    if (whichInteger < 0) then
        set sign = -1
        set whichInteger = -whichInteger
    endif

    // Check if there needs to be commas
    if (whichInteger < 1000) then
        return I2S(whichInteger * sign) // No commas to add
    endif
    
    // Convert to string and iterate
    set t = I2S(whichInteger)
    loop
        // We are working backwards so it may be a bit confusing
        set i = StringLength(t)
        // As long as the number of digits is 3 or more, we can work with it
        if (i > 2) then
            // Set it to the last three digits in t and concatenate it with s
            set s = SubString(t, i - 3, i) + s
            // Remove those three digits from t
            set t = SubString(t, 0, i - 3)
        else
            // It has less than three digits, so we can just slap the rest into s
            set s = t + s
            set b = true
        endif
        if (b == false) then
            // We've still got more digits, so we need a comma
            set s = "," + s
        else
            // No more digits, exit the loop
            exitwhen true
        endif
    endloop

    // Add the negative sign if the original was negative
    if (sign == -1) then
        set s = "-" + s
    endif

    return s
endfunction

Remember, you can only use this with the range -2147483647 to 2147483647.

Here's my entire test code if you want to try it out.

JASS:
function AddCommas takes integer whichInteger returns string
    local integer sign = 1
    local string s = ""
    local string t = ""
    local integer i = 0
    local boolean b = false

    // Store the sign and if negative, make whichInteger positive so we don't have to deal with that nasty negative dividend stuff
    if (whichInteger < 0) then
        set sign = -1
        set whichInteger = -whichInteger
    endif

    // Check if there needs to be commas
    if (whichInteger < 1000) then
        return I2S(whichInteger * sign) // No commas to add
    endif
    
    // Convert to string and iterate
    set t = I2S(whichInteger)
    loop
        // We are working backwards so it may be a bit confusing
        set i = StringLength(t)
        // As long as the number of digits is 3 or more, we can work with it
        if (i > 2) then
            // Set it to the last three digits in t and concatenate it with s
            set s = SubString(t, i - 3, i) + s
            // Remove those three digits from t
            set t = SubString(t, 0, i - 3)
        else
            // It has less than three digits, so we can just slap the rest into s
            set s = t + s
            set b = true
        endif
        if (b == false) then
            // We've still got more digits, so we need a comma
            set s = "," + s
        else
            // No more digits, exit the loop
            exitwhen true
        endif
    endloop

    // Add the negative sign if the original was negative
    if (sign == -1) then
        set s = "-" + s
    endif

    return s
endfunction

//==============================================================================
//  Logarithm script by X - Version 1.0 - December 12, 2009
//==============================================================================
//
//  about:
//      - compute natural logarithm of a real.
//      - compute logarithm to the base b of a real.
//       
//  Usage:
//      - Ln(x)   to compute the natural logarithm of the real x
//      - LogB(x, b) to compute the logarithm to the base b of the real x
//      - LogBV2(x, b) to compute the logarithm to the base b of the real x with another method, see Notes
//      - Logarithm_e to acces the value of the constant e
//
//  Notes:
//      - Ln(x) is exactly the same as LogB(x,Logarithm_e)
//      - LogBV2(x,b) is Ln(x)/Ln(b)  , make your own tests to compare it to LogB(x,b)
//      
//      - you can find the algorithm used at this address :
//              [url]http://en.literateprograms.org/Logarithm_Function_%28Python%29[/url]
//              it is the same as the basic one explained by Donald E. Knuth in his book
//
//      - reals in jass are not very precise, something like 9 total digits. Be happy if it works
//
//  Requirements:
//      - JassHelper.
//
//  Installation:
//      - Create a new trigger called Logarithm.
//      - Convert it to custom text and replace all the code with this code.
//
//  Special Thanks:
//      - Ammorth: for is LinkedList information layout 
//
//==============================================================================

library Logarithm

   globals
       public constant real e = 2.718282  //e=2.71828182845904523536
       private constant real EPSILON = 0.0000001 // dont use lower values, jass reals sucks
   endglobals
    
    function Ln takes real x returns real
        local real decimal = 0.0
        local real partial = 0.5
        local integer i = 0
        if x <= 0 then
            return 0
        endif
        loop
            exitwhen x >= 1
            set i = i - 1
            set x = x * e
        endloop
        loop
            exitwhen x < e
            set i = i + 1
            set x = x / e
        endloop
        set x = Pow(x,2)  // maybe power is more accurate than x*x -_-'
        loop
            exitwhen partial <= EPSILON
            if x >= e then
                set decimal = decimal + partial
                set x = x / e
            endif
            set partial = partial * 0.5
            set x = Pow(x,2)
        endloop
        return i + decimal
    endfunction

    function LogBV2 takes real x, real base returns real
            return Ln(x)/Ln(base) 
    endfunction
    function LogB takes real x, real base returns real
        local real decimal = 0.0
        local real partial = 0.5
        local integer i = 0
        if x <= 0 or base <=0 then
            return 0
        endif
        loop
            exitwhen x >= 1
            set i = i - 1
            set x = x * base
        endloop
        loop
            exitwhen x < base
            set i = i + 1
            set x = x / base
        endloop
        set x = Pow(x,2)
        loop
            exitwhen partial <= EPSILON
            if x >= base then
                set decimal = decimal + partial
                set x = x / base
            endif
            set partial = partial * 0.5
            set x = Pow(x,2)
        endloop
        return i + decimal
    endfunction
   
    function Log takes real x returns real
        return LogB(x, 10)
    endfunction
endlibrary
//==============================================================================
//  End of Logarithm script
//==============================================================================

// TEST CODE PORTION

scope myScope initializer init
    private function init takes nothing returns nothing
        call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, AddCommas(2147483647))
    endfunction
endscope

To use it, just copy the entire script omitting the test code portion at the bottom into a new trigger converted to custom text.

Now you can do something like

  • Custom Script: set udg_MyStringVariable = AddCommas(udg_MyIntegerVariable)
Now you can just use MyStringVariable (GUI Global Variable) anywhere you want it.
 
Last edited:
Level 13
Joined
Mar 24, 2010
Messages
950
+rep and thanks alot for the effort man :) but thats some long code for all i need to do, i dont need to worry about anything over 999 million

  • test Work
    • Events
      • Player - Player 1 (Red) types a chat message containing -num as A substring
    • Conditions
    • Actions
      • Set Temp_Integer = (Integer((Substring((Entered chat string), 6, (Length of (Entered chat string))))))
      • Game - Display to (All players) for 4.00 seconds the text: Temp_String
      • -------- ^ testing ^ --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Temp_Integer Greater than 999
        • Then - Actions
          • Set Temp_Integer2 = (Temp_Integer mod 1000)
          • Set Temp_Integer = (Temp_Integer / 1000)
          • Set Temp_String = (String(Temp_Integer2))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Temp_Integer Greater than 999
            • Then - Actions
              • Set Temp_Integer2 = (Temp_Integer mod 1000)
              • Set Temp_Integer = (Temp_Integer / 1000)
              • Set Temp_String = ((String(Temp_Integer)) + (, + ((String(Temp_Integer2)) + (, + Temp_String))))
            • Else - Actions
              • Set Temp_String = ((String(Temp_Integer)) + (, + (String(Temp_Integer2))))
        • Else - Actions
          • Set Temp_String = (String(Temp_Integer))
      • Game - Display to (All players) for 4.00 seconds the text: Temp_String
I did what i needed here, and yeah i coulda put it in a loop and shortened it a tiny bit but im already using int A and int B and didnt wanna bother with it.
Just in case anyone else ever wanted somethin like this just figured i'd post it
 
Last edited:
Here's non GUI solution

http://www.hiveworkshop.com/forums/1875400-post370.html

JASS:
library AddCommas
    function AddCommas takes integer n returns string
        local integer m = 0
        local string s = ""
        loop
            exitwhen n == 0
            if (m > 100) then
                set s = "," + s
            endif
            set m = n
            set n = n/1000
            set m = m-n*1000
            set s = I2S(m) + s
        endloop
        if (s == "") then
            return "0"
        endif
        return s
    endfunction
endlibrary

hf, now to run to class o-o. Coded that in like... 15 seconds, rofl.


And Bond, your solution is wrong from the 1 line I read (GUI hurts my eyes).

->Temp_Integer Greater than 999

incorrecto ;P
 
Last edited:
oh my o-o, I see that now. Let me check ;D

Tx sevo

edit
Updated and now working
JASS:
library AddCommas
    function AddCommas takes integer n returns string
        local integer m = 0
        local string s = ""
        local boolean b = false
        if (n < 0) then
            set n = -n
            set b = true
        endif
        loop
            exitwhen n == 0
            if (m > 0) then
                set s = "," + s
            endif
            set m = n
            set n = n/1000
            set m = m-n*1000
            if (n > 0) then
                if (m < 10) then
                    set s = "00" + I2S(m) + s
                elseif (m < 100) then
                    set s = "0" + I2S(m) + s
                else
                    set s = I2S(m) + s
                endif
                set m = 1
            else
                set s = I2S(m) + s
                set m = 0
            endif
        endloop
        if (s == "") then
            return "0"
        endif
        if (b) then
            set s = "-" + s
        endif
        return s
    endfunction
endlibrary

test
JASS:
struct tester extends array
    private static method onInit takes nothing returns nothing
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, AddCommas(-30000000))
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, AddCommas(-3000000))
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, AddCommas(-300000))
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, AddCommas(-30000))
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, AddCommas(-3000))
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, AddCommas(-300))
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, AddCommas(-30))
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, AddCommas(-3))
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, AddCommas(0))
    endmethod
endstruct
 
Level 5
Joined
Dec 4, 2006
Messages
110
It's because yours uses pure math. While way more efficient, it sacrifices zeroes. That's why this requires strings.

By the way, mine doesn't require log. Not anymore. I can't easily do anything as I'm on my iPod touch but you only need my AddCommas function.

Also nestharus is right about your code being wrong. Right now mine is the only script here hat works 100% of the time. Albeit it's slow but it works.
 
Level 13
Joined
Mar 24, 2010
Messages
950
Besides the fact that mine works what makes you think that it doesn't? lol

its good for anything up to 999,999,999 which is all i need. I didnt put it in a loop for certain reasons also it wouldn't make it a ton shorter anyway if i did.
 
Level 13
Joined
Mar 24, 2010
Messages
950
oh my bad i missed his update yea didnt even think about int's not holding leading 0's didnt work with using a string to store it either.. or a 'real' weird..

anyway it bothered me so i ended up dinking with it to fix. here it is gui style if anyone ever wants it. the numbers are blue so i made the commas white. The trigger im using this starts it off blue and ends it with |r at end also.

  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Temp_Integer Greater than 999
    • Then - Actions
      • Set Temp_String = (String((Temp_Integer mod 1000)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Length of Temp_String) Equal to 2
        • Then - Actions
          • Set Temp_String = (0 + Temp_String)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Length of Temp_String) Equal to 1
            • Then - Actions
              • Set Temp_String = (00 + Temp_String)
            • Else - Actions
      • Set Temp_Integer = (Temp_Integer / 1000)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Temp_Integer Greater than 999
        • Then - Actions
          • Set i = (Temp_Integer mod 1000)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Length of (String(i))) Equal to 2
            • Then - Actions
              • Set Temp_String = (0 + ((String(i)) + (|r,|cff5BFFFB + Temp_String)))
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Length of (String(i))) Equal to 1
                • Then - Actions
                  • Set Temp_String = (00 + ((String(i)) + (|r,|cff5BFFFB + Temp_String)))
                • Else - Actions
                  • Set Temp_String = ((String(i)) + (|r,|cff5BFFFB + Temp_String))
          • Set Temp_Integer = (Temp_Integer / 1000)
          • Set Temp_String = ((String(Temp_Integer)) + (|r,|cff5BFFFB + Temp_String))
        • Else - Actions
          • Set Temp_String = ((String(Temp_Integer)) + (|r,|cff5BFFFB + Temp_String))
    • Else - Actions
      • Set Temp_String = (String(Temp_Integer))
i still may just use Nestharus's but wanted to finish it up anyway :p
fully tested and works :)
 
Level 13
Joined
Mar 24, 2010
Messages
950
I forgot wc doesn't work with large math functions as fast as it can manipulate strings much like python so i made this real quick for the most efficient way i can think of.. (Without using a intA/intB loop because i use this in a subroutine within a function using those already.) Works as is up to 999,999,999

  • New Comma sys
    • Events
      • Player - Player 1 (Red) types a chat message containing -num as A substring
    • Conditions
    • Actions
      • Set Temp_Integer = (Integer((Substring((Entered chat string), 6, (Length of (Entered chat string))))))
      • Set Temp_String = (String(Temp_Integer))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Temp_Integer Greater than 999
        • Then - Actions
          • Set Temp_String2 = (Substring(Temp_String, ((Length of Temp_String) - 2), (Length of Temp_String)))
          • Set Temp_Integer = (Temp_Integer / 1000)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Temp_Integer Greater than 999
            • Then - Actions
              • Set Temp_String = (Substring(Temp_String, ((Length of Temp_String) - 5), ((Length of Temp_String) - 3)))
              • Set Temp_Integer = (Temp_Integer / 1000)
              • Set Temp_String = ((String(Temp_Integer)) + (, + (Temp_String + (, + Temp_String2))))
            • Else - Actions
              • Set Temp_String = ((String(Temp_Integer)) + (, + Temp_String2))
        • Else - Actions
      • Game - Display to (All players) for 4.00 seconds the text: Temp_String

fully tested and works :)
 
Last edited:
Level 13
Joined
Mar 24, 2010
Messages
950
I forgot wc doesn't work with large math functions as fast as it can manipulate strings much like python

You think wc is fast at doing large math functions dealing with nums in the 32bit+ range? wc is terrible with large math it doesnt even have a very good built in random math function lol. (its terrible compared to any normal programming lang. that is)

everything takes a fraction of a micro second anyway so whats it really matter?

its easy to move down the built in array of a string to cut it into how you want it to look in almost any programming lang.

besides not only does yours also deal with string manipulation also it does a lot of math in loops too. mines more straight to the point and shorter.
 
Level 5
Joined
Dec 4, 2006
Messages
110
Mine uses a comparison and subtraction... That's not a lot.

Nestharus' uses a comparison, division, subtraction, and a multiplication... That's not a lot either.

Not to mention mine has string manipulation, which makes his little bit of extra math actually faster.

Also, the speed and efficiency does matter. If you intend to use this in any semblance of a map then efficiency is pretty important.

No one said WC3 was fast at doing math functions.

The only statement is that WC3 is faster at math than at strings.

While it's bad with math, it's still better at math than strings... That's what we're saying...

Yours is slow and actually longer.

If you don't believe me, convert it to JASS and compare.
 
Another thing...

Remember that strings are char arrays. Whenever you create a new string, it allocates a new permanent char array that stays in memory until the map ends (network char arrays are actually a bit dif from the norm).

So you want to work with strings as little as possible to minimize the allocated char arrays ;P. This is why people say that strings leak.
 
Level 13
Joined
Mar 24, 2010
Messages
950
lol i wonder why wc has so many probs with that, why so many leaks with so many different things. It should have been made to auto remove that not require a extra script on our part to do it. Is their any script that removes those char arrays that stay in mem too or no..

also so your saying that my first one above that works will execute faster than my 2nd one..? Its less lines of code so not sure why


this is the whole function,
All methods do about the same string manipulation do to the fact 00s have to be added depending on the situation anyway
JASS:
function Trig_Comma_Func001Func003C takes nothing returns boolean
    if ( not ( udg_int > 999 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Comma_Func001C takes nothing returns boolean
    if ( not ( udg_int > 999 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Comma_Actions takes nothing returns nothing
    if ( Trig_Comma_Func001C() ) then
        set udg_str2 = SubStringBJ(udg_str, ( StringLength(udg_str) - 2 ), StringLength(udg_str))
        set udg_int = ( udg_int / 1000 )
        if ( Trig_Comma_Func001Func003C() ) then
            set udg_str = SubStringBJ(udg_str, ( StringLength(udg_str) - 5 ), ( StringLength(udg_str) - 3 ))
            set udg_int = ( udg_int / 1000 )
            set udg_str = ( I2S(udg_int) + ( "," + ( udg_str + ( "," + udg_str2 ) ) ) )
        else
            set udg_str = ( I2S(udg_int) + ( "," + udg_str2 ) )
        endif
    else
    endif
endfunction
 
Last edited:
Level 13
Joined
Mar 24, 2010
Messages
950
I only pasted in there the script of the actual part of the code i need to use, the rest of it was just for sample testing.

I guess i dont fully get why when its fewer lines its still longer? Like i know computers do simple math super fast with int's with the math co-processor but its still taking a certain amount of clock cycles to execute every line of code at any rate, and mine just goes through those lines once as where the others go through more lines a few times a piece in a loop, which makes it even more lines to execute. Alls mine does is move through the char array of a string and store the section it needs which by the time it gets down to low level machine lang. since their CISC, processors have instruction sets to do that easy as well.
I'm a computer networking & systems and electronics engineer student so i have a good base knowledge of this stuff but i'll admit im not the best programmer, i only enjoy programming a small amount because of wc lol other than that its not main interest of mine. I had a few classes with c/c++/python/vb but once i was past the class i didint touch it again much lol. So im sure theres stuff about this you guys can teach me, so if you elaborate on it i will understand.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,286
simple string itteration. Break it appart in groups of 3 characters using sub strings orientated from the right and then combine them together through string concatination with commas inbetween.

For reals, you will need to remember to ignore the decimal places but as they are always in a fixed position it should be a non issue.
 
Level 13
Joined
Mar 24, 2010
Messages
950
That is what i did in my method

  • New Comma sys
    • Events
      • Player - Player 1 (Red) types a chat message containing -num as A substring
    • Conditions
    • Actions
      • Set Temp_Integer = (Integer((Substring((Entered chat string), 6, (Length of (Entered chat string))))))
      • Set Temp_String = (String(Temp_Integer))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Temp_Integer Greater than 999
        • Then - Actions
          • Set Temp_String2 = (Substring(Temp_String, ((Length of Temp_String) - 2), (Length of Temp_String)))
          • Set Temp_Integer = (Temp_Integer / 1000)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Temp_Integer Greater than 999
            • Then - Actions
              • Set Temp_String = (Substring(Temp_String, ((Length of Temp_String) - 5), ((Length of Temp_String) - 3)))
              • Set Temp_Integer = (Temp_Integer / 1000)
              • Set Temp_String = ((String(Temp_Integer)) + (, + (Temp_String + (, + Temp_String2))))
            • Else - Actions
              • Set Temp_String = ((String(Temp_Integer)) + (, + Temp_String2))
        • Else - Actions
      • Game - Display to (All players) for 4.00 seconds the text: Temp_String

fully tested and works :)
 
Status
Not open for further replies.
Top