Decimal To Base 70 Trigger

ShadowInTheD

Active Member
Reaction score
12
The function below is supposed to convert an integer value into base 70 and show it to the player that types in the value (atleast for now). I have two questions regarding this.

1. Does the trigger actually DO what I want, or did I do it completely wrong?
2. If I call it in a completely different trigger, will it display?

JASS:
function Decimal2Base70 takes integer i returns string
local string Alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*"
local string Base70String
local integer tracker = i
local integer tracker2
local integer loopinteger
local integer check = 0
local integer StringInteger = 1
loop
exitwhen check < 0
if i/Pow(70,check) < 1 then
set check = -5
set loopinteger = check - 1
endif
set check = check + 1
endloop
loop
exitwhen loopinteger < 0
set tracker = ModuloInteger(tracker,R2I(Pow(70.0,I2R(loopinteger))))
set tracker2 = i - (70*tracker)
set Base70String = SubString(Base70String,StringInteger,StringInteger)+SubString(Alphabet,tracker2,tracker2)
set tracker = tracker2
set StringInteger=StringInteger+1
set loopinteger = loopinteger-1
endloop
call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"Base 70:" + Base70String)
endfunction


As a completely off question that I still need, is there a native function or something that will break a loop immediately?
 

No_exit

Regular User (What is Custom User Title?)
Reaction score
40
1. Does it do what you want?
No.

I had to rewrite most of the code but I managed to get it work.

JASS:
function Decimal2Base70 takes player pl, integer i returns string //Takes a player now too so to call it do something like "call Decimal2Base70(GetTriggerPlayer(),70)"
    local string Alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$^&*?" //Removed % and added ?, apparantly the % char doesn't work in strings.
    local string Base70String = "" //Now initialized.
    local integer tracker
    local integer loopinteger
    local integer check = 1 //now initialized at 1 to allow the number 0 to be properly displayed as 1 digit. If you don't want this then put it at 0.
    loop
        if i/Pow(70,check) < 1 then
            set loopinteger = check-1
            exitwhen true //Exits loop. Always.
        endif
        set check = check + 1
    endloop
    
    loop
        exitwhen loopinteger < 0
        set tracker = ModuloInteger(i,70)
        set i = i / 70
        set Base70String = SubString(Alphabet,tracker,tracker+1) + Base70String
        set loopinteger = loopinteger-1
    endloop
    call DisplayTimedTextToPlayer(pl,0,0,60,"Base 70:" + Base70String) //Now displays for 60 seconds.
    return Base70String //Now actually returns a string.
endfunction


2. If I call it in a completely different trigger, will it display?
The function above will. The original function had a GetTriggerPlayer() in the end which is not very nice since it means that when calling this function you will need to keep in mind that a playerevent happened.

3. As a completely off question that I still need, is there a native function or something that will break a loop immediately?
exitwhen true
as displayed in the code.
 
Reaction score
341
JASS:
function Decimal2Base70 takes integer int returns string
    local string alpha  = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$^&*%%"
    local integer base  = StringLength(alpha)
    local integer one   = 0
    local integer two   = int
    local string output = ""
    
    if int < base then
        return SubString(alpha, int, int + 1)
    endif
    
    loop
        exitwhen two <= 0
        set one = two - (two / base) * base
        set two = two / base
        set output = SubString(alpha, one, one + 1) + output
    endloop
    return output
endfunction


% works, i'm pretty sure you just need to add two of them.
 

ShadowInTheD

Active Member
Reaction score
12
No_Exit, I don't think it's working quite right? Like, 393 is putting 1N, and 71 is putting 1. Do you know what the problem is? It's not putting them together right..
 

ShadowInTheD

Active Member
Reaction score
12
Actually Happy, yours doesn't work well either ^^. If I enter like: 290, 390, and 490, it always returns "1K", and like 289, 389, and 489 returns "1J" ><
 

ShadowInTheD

Active Member
Reaction score
12
WHY WON'T THIS DISPLAY?!?!?!!?!?!!
JASS:
function Decimal2Base70 takes player pl, integer i returns string
  local integer tracker = i
  local integer tracker2
  local integer loopinteger
  local string Alphabet = &quot;0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$^&amp;*?&quot;
  local string output = &quot;&quot;
    loop
        if i/R2I(Pow(70,loopinteger)) &lt; 1 then
        set loopinteger = loopinteger-1
        exitwhen true
        endif
      set loopinteger = loopinteger + 1
    endloop
    loop
      exitwhen loopinteger &lt; 0
        set tracker2 = tracker/R2I(Pow(70,loopinteger))
        set output = SubString(output,tracker2,tracker2+1) + output
        set tracker = tracker - (tracker2 * R2I(Pow(70,loopinteger)))
        set loopinteger = loopinteger-1
    endloop
    call DisplayTimedTextToPlayer(pl,0,0,60,&quot;Base 70:&quot; + output)
    return output
endfunction
 

No_exit

Regular User (What is Custom User Title?)
Reaction score
40
Tested mine too,
393 gives 5h
71 gives 11

I think you are are calling the wrong function or you haven't copied the function right because TriggerHappy's function seems right too.

@ the previous post, you need to initialize loopinteger
local integer loopinteger = 0
 

ShadowInTheD

Active Member
Reaction score
12
First of all, obviously none of these will "work," at least, in the sense that I'm thinking of (maybe you tried to do it just for the sense I was thinking of). But the lines:
JASS:
 set output = SubString(output,tracker2,tracker2+1) + output

creates the string in the wrong order :D.

+ rep =)

Why can't it go past 70^6-1?

What's the highest storing value of an int?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top