- Joined
- Sep 26, 2009
- Messages
- 9,534
The problem could be that you have TableArrays declared as Tables. You shouldn't be using typecasting between Tables and TableArrays.
itemDropTable[this][itemIdTable[this][L]]
itemIdTable[this][L]
itemDropTable[this][item type]
set unitTypeTable[ this.unitTypeId] = this
since you are reassigning table index to be used on death event each time item table is declared for type T, meaning: with your currect create method, I can not have multiple tables for given unit type, like 'hpea'. Instead of allocating new instance you should have checked if such unitType table is already found and allocated. If so, just use recovered index instead.// where 'r' is random int from 1 to weight
if r > weights[L1 - 1] and r < weights[L1] then
what happens if we roll exactly 'border' number? (lets say 20 in your test map). There is no "=" operator within if statement, thus such item will never be found.From what I understood, problem occurs when there are multiple item tables declares, meaby even to the same unit type.
Problem may lie within:set unitTypeTable[ this.unitTypeId] = this
since you are reassigning table index to be used on death event each time item table is declared for type T, meaning: with your currect create method, I can not have multiple tables for given unit type, like 'hpea'. Instead of allocating new instance you should have checked if such unitType table is already found and allocated. If so, just use recovered index instead.
Provide demo code with which you are testing your bugs, would help a lot.
function addToTable takes nothing returns nothing
local ItemDropSystem data = ItemDropSystem.createForType( 'hpea')
call data.addItem( 'afac', 20)
call data.addItem( 'ratc', 20)
call data.addItem( 'rat6', 20)
call data.addItem( 'rat9', 20)
call data.addItem( 'rst1', 100)
set data = ItemDropSystem.createForType( 'hfoo')
call data.addItem( 'rag1', 100)
endfunction
method addItem takes integer itemId, integer weight returns nothing
set this.index = this.index + 1
set this.ttlWeight = this.ttlWeight + weight
set itemIdTable[this][index] = itemId
call BJDebugMsg( " Struct instance = " + I2S( this) + " Item Id = " + I2S( itemIdTable[this][index]) + " = " + I2S( itemId))
set itemDropTable[this][itemId] = this.ttlWeight
call BJDebugMsg( " Struct instance = " + I2S( this) + " Item weight " + I2S( itemDropTable[this][itemId]) + " = " + I2S( this.ttlWeight))
endmethod
private method dropItem takes real x, real y returns boolean
local integer r
local integer L = 1
local integer L1 = 1
local integer end = 0
local integer array weights
set weights[0] = 0
if this != 0 then
loop
exitwhen L > this.index
set weights[L] = itemDropTable[this][itemIdTable[this][L]]
call BJDebugMsg( " Struct Instance = " + I2S( this) + " Item # = " + I2S( L) + " Unit type id = " + I2S( this.unitTypeId) + " Item Id = " + I2S( itemIdTable[this][L]) + " Weight = " + I2S( itemDropTable[this][itemIdTable[this][L]]))
set end = end + 1
set L = L + 1
endloop
set L = 1
loop
exitwhen L > this.multiDrop
set r = GetRandomInt( 1, this.ttlWeight)
loop
exitwhen L1 > end
if r > weights[L1 - 1] and r <= weights[L1] then
call CreateItem( itemIdTable[this][L1], x, y)
endif
set L1 = L1 + 1
endloop
set L = L + 1
endloop
endif
return this.dropTypeTableAlso
endmethod
B) there are many flaws within your code, like:
// where 'r' is random int from 1 to weight if r > weights[L1 - 1] and r < weights[L1] then
what happens if we roll exactly 'border' number? (lets say 20 in your test map). There is no "=" operator within if statement, thus such item will never be found.
Searching and indexing could be improved a lot, however, this is not the case now.
// where 'r' is random int from 1 to weight
if r > weights[L1 - 1] and r <= weights[L1] then
static method createForType takes integer unitTypeId returns thistype
local thistype this = thistype.allocate()
set this.unitTypeId = unitTypeId
set unitTypeTable[ this.unitTypeId] = this
set this.specificUnit = false
set this.dropTypeTableAlso = false
call this.setValues()
return this
endmethod
static method createForUnit takes unit u, boolean dropTypeTableAlso returns thistype
local thistype this = thistype.allocate()
set this.unitTypeId = GetHandleId( u)
set unitIdTable[ this.unitTypeId] = this
set this.specificUnit = true
set this.dropTypeTableAlso = dropTypeTableAlso
call this.setValues()
return this
endmethod
static method createForType takes integer unitTypeId returns thistype
local thistype this
if unitTypeTable[ this.unitTypeId] == 0 then // is allocated?
set this = thistype.allocate()
set this.unitTypeId = unitTypeId
set unitTypeTable[ this.unitTypeId] = this
set this.specificUnit = false
set this.dropTypeTableAlso = false
call this.setValues()
else
set this = unitTypeTable[ this.unitTypeId]
endif
return this
endmethod
deathismyfriend, the main point is that you have the variables declared wrong. You can't set a Table to a TableArray index, and then not typecast that Table back to TableArray each time you use it. Just declare it as a TableArray.
You should change your name, everyone is mistyping it,like deathismyfriend did.
No I am not ;>
I've already stated, Spin, was not my real nick. Its my bros.
And btw, there is only 1 nickname change per lifetime on hive![]()
set a[654321] = 'A' //<-------
set a[54321] = 'B' //<-------
set a.unit[12345] = GetTriggerUnit()
set a.unit[GetHandleId(a.unit[12345])] = GetSpellTargetUnit()
set a.real['ABCD'] = 3.14159
set a.integer[133] = 21
local integer array i
set i['a'] = 24
set i['b'] = 25
set i['c'] = 26
// equivalent to
set i[97] = 24
set i[98] = 25
set i[99] = 26
It is just assigning the integer 'A' and integer 'B' to particular keys in the table instance "a".
a -> key 654321 -> 'A'
a -> key 54321 -> 'B'
'A' and 'B' are integers. The apostrophe 'XXXX' notation is normally used for rawcodes. Rawcodes are just formed from ASCII characters, e.g. 'a' corresponds to 97. When you have a code such as 'abcd', it'll use an algorithm to generate an integer representation.
We use raw codes all the time for unit types, abilities, etc. But as for the individual 'a' or 'b', you won't find too many uses except in specific cases. For example, dialogs provide an option for a hotkey, and you can input 'a' or 'b', etc. to determine the hotkey (since it takes an integer, not a string). You can also use it for some weird array mechanic, if you want to be fancy:
JASS:local integer array i set i['a'] = 24 set i['b'] = 25 set i['c'] = 26 // equivalent to set i[97] = 24 set i[98] = 25 set i[99] = 26
set a.integer[654321] = 'A'
set a.integer[54321] = 'B'
Thanks for the explanation. But why not just use this if 'A' and 'B' are considered integers:
JASS:set a.integer[654321] = 'A' set a.integer[54321] = 'B'
That option wasn't added until later requested by Spinnaker. Before, you had to save integers without the ".integer". It might've been for backwards compatibility/similarity with Vexorian's Table.
Oh, got it, thnx a lot!PnF, you seems the only active mod on Hive now.
![]()
I'm always trolling the forums I just don't have any time lately to get intellectual due to work sapping all my creativity.
local TableArray da = TableArray[0x2000]
on your example, why do you have an x in integer?weathereffect
. LoadWeatherEffectHandle
.weathereffect
and possibly terraindeformation
.TableArray A = TableArray[5]
TableArray B = TableArray[5]
// First action
set A[1].integer[5] = 5
// Second one
set B[1].integer[5] = 6
TableArray[xx]
will create 5 Tables and return them to you, so they are completly different.It shouldnt, sinceTableArray[xx]
will create 5 Tables and return them to you, so they are completly different.
Try printing A[1] and B[1] and you will see it will not overrite it(it shouldnt at least), because they are different instances(they should be)
can you post whole code, and did you actually teste the integers of A[1] and B[1]?
scope s initializer i
private function i takes nothing returns nothing
local TableArray a = TableArray[5]
local TableArray b = TableArray[5]
call BJDebugMsg(I2S(integer(a[2])))
call BJDebugMsg(I2S(integer(b[2])))
set a[2].integer[4] = 8
set b[2].integer[4] = 11
call BJDebugMsg(I2S(a[2].integer[4]))
endfunction
endscope
set ta=TableArray[size/index]
when it is created set ta[myMissIndex].integer[this]=someValue
Table array ta
because of static method operator []
set ta.integer[parentKey][childKey]=someValue.