TableArray[Parent][ChildIndex]
in post #93...tb[1][2] = 3
tb[2][1] = 3
struct S extends array
static TableArray ta
/* Is basically 'the same' as */
Table t
method m ....
set ta[this]['A000'] = 1
set this.t['A000'] = 2
if ta[this]['A000'] == 1 then
endif
if this.t['A000'] == 2 then
endif
endmethod
endstruct
struct Hash extends array
private static constant integer DEFAULT_SIZE = 0x2000
private static TableArray array H4X
static method operator [] takes integer i returns TableArray
if H4X[i] == 0 then
set H4X[i] = TableArray[DEFAULT_SIZE]
endif
return H4X[i]
endmethod
endstruct
// ...
set Hash[4680][1212]['A!8*'] = 9
// ...
3DArray[GetUnitId(unitOne)][GetUnitId(unitDeux)][DATA_TYPE_THREAT]
So it's effectively a Table per unit per unit?
And he's correct, but the order you use them is irrelevant because you would reach the var in the same way anyways...
tb[1][2] = 3
tb[2][1] = 3
However the Parent can't go over 8190 because it's a struct array allocator, but the child is a hashtable index, so it can go beyond.
Anyways, i've never ever had to use TableArray anyways, you can always avoid it
set ai = TableArray[2]
, parent ID's can still be reduced by this set ai[id-id+1][1] = 5
...although you're right about the order...set ai = TableArray[2]
loop
set t = CreateTimer()
set id = GetHandleId(t)
set ai[id-id+1][1] = 88
set ai[id-id+1][2] = 999
set ai[id-id+1].string[1] = "hello"
set ai[id-id+1].string[2] = "table"
call BJDebugMsg(I2S(ai[id-id+1][1]))
call BJDebugMsg(I2S(ai[id-id+1][2]))
call BJDebugMsg(ai[id-id+1].string[1])
call BJDebugMsg(ai[id-id+1].string[2])
//TableArray Error: Tried to double-free instance:
//but this is OK now, suppose to be ourside
call ai.flush()
set i = i-1
set t = null
exitwhen i==0
endloop
set ai[id-id+1][1] = 88
set ai[id-id+1][2] = 999
set ai[id-id+1].string[@3@] = "hello"
set ai[id-id+1].string[@4@] = "table"
[id-id]
is equal to 0, don't know where are you getting atai[1][1] = 88
ai[1][2] = 999
ai[1].string[1] = "hello"
ai[1].string[2] = "table"
ai[TableArray index][hashtable index]
not the other way around.set itemIdTable = TableArray[0x2000]
set itemDropTable = TableArray[0x2000]
set this.index = this.index + 1
set this.percent = this.percent + percents[L]
set itemDropTable[this][index] = this.percent
set itemIdTable[this][index] = itemIds[L]
call BJDebugMsg( I2S( itemDropTable[this][L]))
call BJDebugMsg( I2S( itemIdTable[this][L]))
set itemDropTable[this][index] = this.percent
set itemIdTable[this][index] = itemIds[L]
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
set unitTypeTable = Table.create()
set unitIdTable = Table.create()
set itemIdTable = TableArray[0x2000]
set itemDropTable = TableArray[0x2000]
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_DEATH)
call TriggerAddCondition( t, function thistype.deathEvent)
set t = null
endmethod
method addItem takes integer itemId1, integer percent1, integer itemId2, integer percent2, integer itemId3, integer percent3, integer itemId4, integer percent4, integer itemId5, integer percent5 returns nothing
local integer L = 1
local integer array itemIds
local integer array percents
set itemIds[1] = itemId1
set itemIds[2] = itemId2
set itemIds[3] = itemId3
set itemIds[4] = itemId4
set itemIds[5] = itemId5
set percents[1] = percent1
set percents[2] = percent2
set percents[3] = percent3
set percents[4] = percent4
set percents[5] = percent5
loop
exitwhen L > 5
if itemIds[L] != 0 then
set this.index = this.index + 1
set this.percent = this.percent + percents[L]
set itemDropTable[this][index] = this.percent
set itemIdTable[this][index] = itemIds[L]
call BJDebugMsg( I2S( itemDropTable[this][L]))
call BJDebugMsg( I2S( itemIdTable[this][L]))
endif
set L = L + 1
endloop
if this.percent > 100 then
call BJDebugMsg( "|c00ff0303WARNING|r |cffffcc00Please Change The Percents of the Items for unit with Item Type Id = |c00ff0303" + I2S( this.unitTypeId) + "|r
|cffffcc00as the items are over 100% which will cause bugs|r |c00ff0303WARNING|r")
endif
endmethod
You are debugging [this ][ L ], but it looks like you need to debug [this ][ index ].
0x2000
is 8192
in base 16.scope BUG
struct Bug
static Table t
static method onInit takes nothing returns nothing
local effect sfx = AddSpecialEffect("Abilities\\Spells\\NightElf\\Starfall\\StarfallCaster.mdl", 0,0)
set t = Table.create()
set t.effect[123] = sfx
set t.player[123] = Player(1) //if I disable this line, it will work
call DestroyEffect(t.effect[123])
endmethod
endstruct
endscope
scope BUG
struct Bug
static hashtable h = InitHashtable()
static method onInit takes nothing returns nothing
local effect sfx = AddSpecialEffect("Abilities\\Spells\\NightElf\\Starfall\\StarfallCaster.mdl", 0,0)
call SaveEffectHandle(h, 123, 1, sfx)
call SavePlayerHandle(h, 123, 2, Player(1))
call DestroyEffect(LoadEffectHandle(h, 123, 1))
endmethod
endstruct
endscope
if someTable[id] > SomeConstantInt then
set someTable[id] = someTable[id] + 1
endif
Question.
How do i compare integers saved in the Table?
I tried something like this:
But,errors says that I cannot compare Relative Type to Native Type.JASS:if someTable[id] > SomeConstantInt then set someTable[id] = someTable[id] + 1 endif
Question.
How do i compare integers saved in the Table?
I tried something like this:
But,errors says that I cannot compare Relative Type to Native Type.JASS:if someTable[id] > SomeConstantInt then set someTable[id] = someTable[id] + 1 endif
if someTable[id] > SomeConstantInt then
if (someTable[id] > SomeConstantInt) then
BTW, normal hashtable works;
JASS:struct Bug static hashtable h = InitHashtable() static method onInit takes nothing returns nothing local effect sfx = AddSpecialEffect("Abilities\\Spells\\NightElf\\Starfall\\StarfallCaster.mdl", 0,0) call SaveEffectHandle(h, 123, 1, sfx) call SavePlayerHandle(h, 123, 2, Player(1)) call DestroyEffect(LoadEffectHandle(h, 123, 1)) endmethod endstruct
struct Bug
static hashtable h = InitHashtable()
static method onInit takes nothing returns nothing
local effect sfx = AddSpecialEffect("Abilities\\Spells\\NightElf\\Starfall\\StarfallCaster.mdl", 0,0)
call SaveEffectHandle(h, 123, 1, sfx)
call SavePlayerHandle(h, 123, 1, Player(1))
call DestroyEffect(LoadEffectHandle(h, 123, 1)) // You're screwed :(
endmethod
endstruct
Mind if I ask why?, coz as I said the normal HT works, not the Table...Why would that not work? I think you should compare to this
You're screwed![]()
call SavePlayerHandle(h, 123, 2, Player(1))
call SavePlayerHandle(h, 123, 1, Player(1))
The code in post #131 is very short so it's so easy to check it, anyway, here's a sample map to prove it...it's all but 100% of the time usage error.
Found a nasty bug...
so the player and effect share the same childKey?JASS:scope BUG struct Bug static Table t static method onInit takes nothing returns nothing local effect sfx = AddSpecialEffect("Abilities\\Spells\\NightElf\\Starfall\\StarfallCaster.mdl", 0,0) set t = Table.create() set t.effect[123] = sfx set t.player[123] = Player(1) //if I disable this line, it will work call DestroyEffect(t.effect[123]) endmethod endstruct endscope
EDIT:
BTW, normal hashtable works;
JASS:scope BUG struct Bug static hashtable h = InitHashtable() static method onInit takes nothing returns nothing local effect sfx = AddSpecialEffect("Abilities\\Spells\\NightElf\\Starfall\\StarfallCaster.mdl", 0,0) call SaveEffectHandle(h, 123, 1, sfx) call SavePlayerHandle(h, 123, 2, Player(1)) call DestroyEffect(LoadEffectHandle(h, 123, 1)) endmethod endstruct endscope
so the player and effect share the same childKey?
Obvioulsy yes, not hard to check anyway, the code is available.
So it's not a bug just an expected behavior, but yes you have to we aware about this.
If you really need to store different types of handle just use a struct.
/*
| method flush takes nothing returns nothing
| flush all stored values inside of it
|
| method remove takes integer key returns nothing
| remove the value at index "key"
|
| method operator []= takes integer key, $TYPE$ value returns nothing
| assign "value" to index "key"
|
| method operator [] takes integer key returns $TYPE$
| load the value at index "key"
|
| method has takes integer key returns boolean
| whether or not the key was assigned
*/
Table
is an unacceptable name.