Hi ! I'm currently trying to implement a dynamic random unit sell system and I've ran into a strange problem using the native function which adds unit to a shop (AddUnitToStockBJ).
-
-
- Previous drafted units and both hashtables are flushed with the following code
Thanks for your help
Problem
Sometimes the function is adding the correct amount of unit slots to the shop and sometimes it just doesn't. I'm sure the integer variable for slots is ok as I check it just before the function call (check picture provided)Context
This function is called each time the Roll ability is casted and this is happening before :-
udg_hashDraftedUnits
saves the 5 random unit-types as follows -> INDEX of PLAYER_NUMBER-
udg_hashCurrentDrafterUnits
saves the number of occurences by drafted unit-type-> UNIT_TYPE_ID of PLAYER_NUMBER- Previous drafted units and both hashtables are flushed with the following code
-
Flushing Tables
-
Events
-
Conditions
-
Actions
-
For each (Integer iteratorInt[(Player number of (Triggering player))]) from 1 to 5, do (Actions)
-
Loop - Actions
-
-------- Cleaning the drafter for the new roll --------
-
Custom script: set unitTypeId = LoadIntegerBJ(udg_iteratorInt[playerIndex], playerIndex, udg_hashDraftedUnits)
-
Custom script: set udg_utUnitLoaded[playerIndex] = unitTypeId
-
Neutral Building - Remove utUnitLoaded[(Player number of (Triggering player))] from DRAFTERS[(Player number of (Triggering player))]
-
-
-
-------- Cleaning the old draft hashtables --------
-
Hashtable - Clear all child hashtables of child (Player number of (Triggering player)) in hashCurrentDrafterUnits
-
Hashtable - Clear all child hashtables of child (Player number of (Triggering player)) in hashDraftedUnits
-
-------- Shit Happening --------
-
Custom script: call AddUnitsToDrafter(playerIndex)
-
-
Code
JASS:
function AddUnitsToDrafter takes integer playerIndex returns nothing
local integer unitTypeId
local integer unitCount
local Stack unitTypeList = Stack.create()
set udg_iteratorInt[playerIndex] = 1
loop
exitwhen udg_iteratorInt[playerIndex] > 5
set unitTypeId = LoadIntegerBJ(udg_iteratorInt[playerIndex], playerIndex, udg_hashDraftedUnits)
set unitCount = LoadIntegerBJ(unitTypeId, playerIndex, udg_hashCurrentDrafterUnits)
call SaveIntegerBJ(( unitCount + 1 ), unitTypeId, playerIndex, udg_hashCurrentDrafterUnits)
if ( not unitTypeList.has(unitTypeId) ) then
call unitTypeList.add(unitTypeId)
endif
set udg_iteratorInt[playerIndex] = udg_iteratorInt[playerIndex] + 1
endloop
call DisplayTextToForce( GetPlayersAll(), "List size : " + I2S(unitTypeList.count) )
loop
exitwhen not unitTypeList.hasNext()
set unitTypeId = unitTypeList.getNext()
set unitCount = LoadIntegerBJ(unitTypeId, playerIndex, udg_hashCurrentDrafterUnits)
call DisplayTextToForce( GetPlayersAll(), "Unit ID " + I2S(unitTypeId) + " : " + I2S(unitCount) )
call AddUnitToStockBJ(unitTypeId, udg_DRAFTERS[playerIndex], unitCount, unitCount)
endloop
endfunction
Thanks for your help