• 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.

[JASS] Help with this trigger

Status
Not open for further replies.
Level 11
Joined
Dec 19, 2012
Messages
411
[jass=My jass]
type sarray extends string array [10]

function BaseConvert takes integer i, integer LI, sarray sa, string fc returns nothing
local integer array I
local integer I2
local integer LI2 = 1
local integer CI
call BJDebugMsg("1")
if R2I(Pow(62, 3)) < i then
set CI = 4
else
if R2I(Pow(62, 2)) < i then
set CI = 3
else
if R2I(Pow(62, 1)) < i then
set CI = 2
else
set CI = 1
endif
endif
endif
loop
set I[LI] = i / R2I(Pow(62, CI-LI))
set I2 = I[LI] * R2I(Pow(62, CI-LI))
loop
exitwhen LI2 > 62
if LI2 == I[LI] then
set sa[LI] = GS[LI2]
set fc = fc + sa[LI]
endif
set LI2 = LI2 + 1
endloop
exitwhen LI > CI
set LI = LI + 1
endloop
endfunction

function Save takes nothing returns boolean
local integer array i
local string fc
local sarray sa = sarray.create()
set i[1] = GetPlayerState( GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD)
call BJDebugMsg("1")
call BaseConvert (i[1], 1, sa, fc)
call DisplayTextToPlayer(GetTriggerPlayer(), 0, 0, fc)
return false
endfunction

//===========================================================================
function InitTrig_Save takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 0
call TriggerAddCondition( t, Filter (function Save))
loop
call TriggerRegisterPlayerChatEvent(t, Player(i), "-save", true)
exitwhen i == bj_MAX_PLAYERS
set i = i + 1
endloop
set t = null
endfunction[/code]


Here's an another trigger related to it.

[jass=My jass]globals
string array GS
endglobals

function Init takes nothing returns boolean
local string s = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
local integer i = 1
loop
exitwhen i > 62
set GS = SubString( s, i, i)
set i = i + 1
endloop
call DestroyTrigger(GetTriggeringTrigger())
return false
endfunction

//===========================================================================
function InitTrig_Init takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerAddCondition( t, Condition(function Init))
set t = null
endfunction[/code]


I have no idea why this trigger stop running, the debug massage only showed "1" one time only. Anyone can help me find the problem?
 
Last edited:
Level 11
Joined
Dec 19, 2012
Messages
411
I already did that, its failed to call the BaseConvert function, and i don't know why it failed to call it (also after failed call, the actions behind the call are also stopped, its like
  • Skip remaining actions
is being added before the function call)
 
Level 11
Joined
Dec 19, 2012
Messages
411
Its probably i explained not too clear, i try to explain more clearer.

JASS:
    local sarray sa = sarray.create()
    set i[1] = GetPlayerState( GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD)
    call BJDebugMsg("1")
    call BaseConvert (i[1], 1, sa, fc)
    call BJDebugMsg("2")

Above, the debug message will only display "1", "2" will never display.


JASS:
function BaseConvert takes integer i, integer LI, sarray sa, string fc returns nothing
    local integer array I
    local integer I2
    local integer LI2 = 1
    local integer CI
    call BJDebugMsg("3")
    if R2I(Pow(62, 3)) < i then
      set CI = 4

As above, I called the BaseConvert function, debug message "3" won't display in game, the only thing i can figured out is function call failed.


fc will be defined when BaseConvert function successfully called.
 
You can't pass a null value into a function. It causes the function to break. If you want to pass an empty string do this.
JASS:
local string fc = ""

Also fc will not be set to this value
JASS:
set fc = fc + sa[LI]
in this function
JASS:
function Save takes nothing returns boolean

You would have to do this to return a value to the save function.

JASS:
function BaseConvert takes integer i, integer LI, sarray sa returns string
    local integer array I
    local integer I2
    local integer LI2 = 1
    local integer CI
    local string fc = ""
    call BJDebugMsg("1")
    if R2I(Pow(62, 3)) < i then
      set CI = 4
        else
        if R2I(Pow(62, 2)) < i then
          set CI = 3
            else
            if R2I(Pow(62, 1)) < i then
              set CI = 2
              else
              set CI = 1
              endif
        endif
    endif
    loop
      set I[LI] = i / R2I(Pow(62, CI-LI))
      set I2 = I[LI] * R2I(Pow(62, CI-LI))
        loop
          exitwhen LI2 > 62
          if LI2 == I[LI] then
            set sa[LI] = GS[LI2]
            set fc = fc + sa[LI]
          endif
          set LI2 = LI2 + 1
        endloop
      exitwhen LI > CI
      set LI = LI + 1
    endloop
    return fc
endfunction

function Save takes nothing returns boolean
    local integer array i
    local string fc
    local sarray sa = sarray.create()
    set i[1] = GetPlayerState( GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD)
    call BJDebugMsg("1")
    set fc = BaseConvert (i[1], 1, sa)
    call DisplayTextToPlayer(GetTriggerPlayer(), 0, 0, fc)
    return false
endfunction

//===========================================================================
function InitTrig_Save takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    call TriggerAddCondition( t, Filter (function Save))
    loop
      call TriggerRegisterPlayerChatEvent(t, Player(i), "-save", true)
      exitwhen i == bj_MAX_PLAYERS
      set i = i + 1
    endloop
    set t = null
endfunction
 
Level 11
Joined
Dec 19, 2012
Messages
411
Oh! I don't even know that, thx for help. And btw i forgot to times back the
I2*R2I(Pow(62, CI-LI)) after the I2.

Also forgot to reset the LI2 after done loop.


EDIT :
OK, i now facing new problem. No matter what i do, the global string array is always return (null). Any idea?

set GS = "" < this totally can't help when added before the Substring.

Another problem, i wonder why fc return failed although it already carried string and still returning null?
 
Last edited:
Level 11
Joined
Dec 19, 2012
Messages
411
The ITE is totally running, well i give you my lastest trigger for better understanding and easier to find problems.

JASS:
globals
    string array GS
endglobals

function Init takes nothing returns nothing
    // Substring failed to function and i can only do like this...
    set GS[1] = "0"
    set GS[2] = "1"
    set GS[3] = "2"
    set GS[4] = "3"
    set GS[5] = "4"
    set GS[6] = "5"
    set GS[7] = "6"
    set GS[8] = "7"
    set GS[9] = "8"
    set GS[10] = "9"
    set GS[11] = "a"
    set GS[12] = "b"
    set GS[13] = "c"
    set GS[14] = "d"
    set GS[15] = "e"
    set GS[16] = "f"
    set GS[17] = "g"
    set GS[18] = "h"
    set GS[19] = "i"
    set GS[20] = "j"
    set GS[21] = "k"
    set GS[22] = "l"
    set GS[23] = "m"
    set GS[24] = "n"
    set GS[25] = "o"
    set GS[26] = "p"
    set GS[27] = "q"
    set GS[28] = "r"
    set GS[29] = "s"
    set GS[30] = "t"
    set GS[31] = "u"
    set GS[32] = "v"
    set GS[33] = "w"
    set GS[34] = "x"
    set GS[35] = "y"
    set GS[36] = "z"
    set GS[37] = "A"
    set GS[38] = "B"
    set GS[39] = "C"
    set GS[40] = "D"
    set GS[41] = "E"
    set GS[42] = "F"
    set GS[43] = "G"
    set GS[44] = "H"
    set GS[45] = "I"
    set GS[46] = "J"
    set GS[47] = "K"
    set GS[48] = "L"
    set GS[49] = "M"
    set GS[50] = "N"
    set GS[51] = "O"
    set GS[52] = "P"
    set GS[53] = "Q"
    set GS[54] = "R"
    set GS[55] = "S"
    set GS[56] = "T"
    set GS[57] = "U"
    set GS[58] = "V"
    set GS[59] = "W"
    set GS[60] = "X"
    set GS[61] = "Y"
    set GS[62] = "Z"

endfunction

function BaseConvert takes integer i, integer LI returns string
    local integer array I
    local integer I2
    local integer LI2
    local integer CI
    local string fc = ""
    if R2I(Pow(62, 3)) < i then
      set CI = 4
        else
        if R2I(Pow(62, 2)) < i then
          set CI = 3
            else
            if R2I(Pow(62, 1)) < i then
              set CI = 2
              else
              set CI = 1
              endif
        endif
    endif
    loop
      exitwhen LI>CI
      call BJDebugMsg(I2S(LI))
      call BJDebugMsg(I2S(CI))
      set I[LI] = i / R2I(Pow(62, CI-LI))
      set I2 = I[LI] * R2I(Pow(62, CI-LI))
      set i = i - I2
      set LI2 = 1
        loop
          exitwhen LI2 > 62
          if LI2 == I[LI] then
            set fc = fc + GS[LI2]
            call BJDebugMsg(fc)
            endif
          set LI2 = LI2 + 1
        endloop
      set LI = LI + 1
    endloop
    return fc
endfunction

function Save takes nothing returns boolean
    local integer array i
    local string fc
    set i[1] = GetPlayerState( GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD)
    call BaseConvert (i[1], 1)
    call BJDebugMsg("FINAL CODE is : " + fc)
    call DisplayTimedTextToPlayer(GetTriggerPlayer(), 0, 0, 180, fc)
    return false
endfunction

//===========================================================================
function InitTrig_Save takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    call TriggerAddCondition( t, Filter (function Save))
    call Init()
    loop
      call TriggerRegisterPlayerChatEvent(t, Player(i), "-save", true)
      exitwhen i == bj_MAX_PLAYERS
      set i = i + 1
    endloop
    set t = null
endfunction

Just copy and paste into a map and try to run this then you will know...

EDIT : Updated, now the "FINAL CODE is :" don't even display out...
EDIT2: Sry that i didnt notice set fc = BaseConvert... Its work now...btw how about the Substring problem?
 
Last edited:
Ok this works.

JASS:
globals
    string array GS
endglobals

function Init takes nothing returns nothing
    // Substring failed to function and i can only do like this...
    set GS[1] = "0"
    set GS[2] = "1"
    set GS[3] = "2"
    set GS[4] = "3"
    set GS[5] = "4"
    set GS[6] = "5"
    set GS[7] = "6"
    set GS[8] = "7"
    set GS[9] = "8"
    set GS[10] = "9"
    set GS[11] = "a"
    set GS[12] = "b"
    set GS[13] = "c"
    set GS[14] = "d"
    set GS[15] = "e"
    set GS[16] = "f"
    set GS[17] = "g"
    set GS[18] = "h"
    set GS[19] = "i"
    set GS[20] = "j"
    set GS[21] = "k"
    set GS[22] = "l"
    set GS[23] = "m"
    set GS[24] = "n"
    set GS[25] = "o"
    set GS[26] = "p"
    set GS[27] = "q"
    set GS[28] = "r"
    set GS[29] = "s"
    set GS[30] = "t"
    set GS[31] = "u"
    set GS[32] = "v"
    set GS[33] = "w"
    set GS[34] = "x"
    set GS[35] = "y"
    set GS[36] = "z"
    set GS[37] = "A"
    set GS[38] = "B"
    set GS[39] = "C"
    set GS[40] = "D"
    set GS[41] = "E"
    set GS[42] = "F"
    set GS[43] = "G"
    set GS[44] = "H"
    set GS[45] = "I"
    set GS[46] = "J"
    set GS[47] = "K"
    set GS[48] = "L"
    set GS[49] = "M"
    set GS[50] = "N"
    set GS[51] = "O"
    set GS[52] = "P"
    set GS[53] = "Q"
    set GS[54] = "R"
    set GS[55] = "S"
    set GS[56] = "T"
    set GS[57] = "U"
    set GS[58] = "V"
    set GS[59] = "W"
    set GS[60] = "X"
    set GS[61] = "Y"
    set GS[62] = "Z"

endfunction

function BaseConvert takes integer i, integer LI returns string
    local integer array I
    local integer I2 = 0
    local integer LI2 = 0
    local integer CI = 0
    local string fc = "?"
    if R2I(Pow(62, 3)) < i then
      set CI = 4
        else
        if R2I(Pow(62, 2)) < i then
          set CI = 3
            else
            if R2I(Pow(62, 1)) < i then
              set CI = 2
              else
              set CI = 1
              endif
        endif
    endif
    loop
      exitwhen LI>CI
      call BJDebugMsg(I2S(LI))
      call BJDebugMsg(I2S(CI))
      set I[LI] = i / R2I(Pow(62, CI-LI))
      set I2 = I[LI] * R2I(Pow(62, CI-LI))
      set i = i - I2
      set LI2 = 1
        loop
          exitwhen LI2 > 62
          if LI2 == I[LI] then
            set fc = fc + GS[LI2]
            call BJDebugMsg(fc)
            endif
          set LI2 = LI2 + 1
        endloop
      set LI = LI + 1
    endloop
    return fc
endfunction

function Save takes nothing returns boolean
    local integer array i
    local string fc = ""
    set i[1] = GetPlayerState( GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD)
    set fc = BaseConvert (i[1], 1)
    call BJDebugMsg("FINAL CODE is : " + fc)
    call DisplayTimedTextToPlayer(GetTriggerPlayer(), 0, 0, 180, fc)
    return false
endfunction

//===========================================================================
function InitTrig_Save takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    call TriggerAddCondition( t, Filter (function Save))
    call Init()
    loop
      call TriggerRegisterPlayerChatEvent(t, Player(i), "-save", true)
      exitwhen i == bj_MAX_PLAYERS
      set i = i + 1
    endloop
    set t = null
endfunction

It displays what is in the picture below.
That means that the way you have your loop set up to add string to fc is incorrect.
This loop is never ran. It exits at the exitwhen statement.

JASS:
loop
      exitwhen LI>CI
      call BJDebugMsg(I2S(LI))
      call BJDebugMsg(I2S(CI))
      set I[LI] = i / R2I(Pow(62, CI-LI))
      set I2 = I[LI] * R2I(Pow(62, CI-LI))
      set i = i - I2
      set LI2 = 1
        loop
          exitwhen LI2 > 62
          if LI2 == I[LI] then
            set fc = fc + GS[LI2]
            call BJDebugMsg(fc)
            endif
          set LI2 = LI2 + 1
        endloop
      set LI = LI + 1
    endloop
 

Attachments

  • Capture.PNG
    Capture.PNG
    7.9 KB · Views: 53
Level 11
Joined
Dec 19, 2012
Messages
411
I got it works now, now just left the Substring function... i wanna know why its failed to substring it?

JASS:
globals
    string array GS
endglobals

function Test takes nothing returns nothing
    local integer i = 0
    local string s = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    loop
      exitwhen i > 62
      set GS[i] = ""
      set GS[i] = SubString(s, i, i)
      call BJDebugMsg("GS STRING IS " + GS[i])
      set i = i + 1
    endloop
endfunction
 
Status
Not open for further replies.
Top