- Joined
- Aug 1, 2013
- Messages
- 4,658
JASS:
struct s
private integer i
private string array s[10]
public method setI takes integer value returns nothing
set i = value
endmethod
public method getI takes nothing returns integer
return i
endmethod
public method setS takes integer index, string value returns nothing
set this.s[index] = value
endmethod
public method getS takes integer index returns string
return this.s[index]
endmethod
public static method getType takes integer i returns thistype
local thistype this = i
if this == null then
set this = thistype.create()
endif
return this
endmethod
endstruct
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
local s s1 = s.getType(1)
local s s2 = s.getType(2)
local s s3 = s.getType(3)
call s1.setI(10)
call s2.setI(11)
call s3.setI(12)
call BJDebugMsg("s1 = " + I2S(s1.getI()))
call BJDebugMsg("s2 = " + I2S(s2.getI()))
call BJDebugMsg("s3 = " + I2S(s3.getI()))
call s1.setS(1, "bla1")
call s2.setS(1, "bla2")
call s3.setS(1, "bla3")
call BJDebugMsg("s1 = " + s1.getS(1))
call BJDebugMsg("s2 = " + s2.getS(1))
call BJDebugMsg("s3 = " + s3.getS(1))
endfunction
The thing is that all 3 objects (s1, s2 and s3) have all a separate integer i, but they have a shared string array s.
As seen in the debug messages:
s1 = 10
s2 = 11
s3 = 12
s1 = bla3
s2 = bla3
s3 = bla3
So how do I make separate arrays?