- Joined
- Jul 30, 2018
- Messages
- 445
Hey!
It's been a while since I coded for Warcraft III (or in general, for that matter), thus my brains are a bit scrambled right now. I am trying to make a simple inventory system that changes all the items for multiple pages of the inventory.
I got it working, actually, as I just brute forced it for the proof of concept, but now I am wondering how I could make the code more efficient. There are two obvious problems: it's not very efficient, and you can't add more pages very easily. My solution would be multidimensional arrays, but as far as I know, JASS doesn't really support them (let alone three-dimensional ones, since I also need a Unit Indexer and the Custom Value of the unit must also be considered). Or if they are supported, could someone maybe give a little explanation on how to implement them? I couldn't find any info on how to use those.
Anyway, any good tips to make it more efficient come to your mind?
Here's a snipped from the most essential part of the code:
It's been a while since I coded for Warcraft III (or in general, for that matter), thus my brains are a bit scrambled right now. I am trying to make a simple inventory system that changes all the items for multiple pages of the inventory.
I got it working, actually, as I just brute forced it for the proof of concept, but now I am wondering how I could make the code more efficient. There are two obvious problems: it's not very efficient, and you can't add more pages very easily. My solution would be multidimensional arrays, but as far as I know, JASS doesn't really support them (let alone three-dimensional ones, since I also need a Unit Indexer and the Custom Value of the unit must also be considered). Or if they are supported, could someone maybe give a little explanation on how to implement them? I couldn't find any info on how to use those.
Anyway, any good tips to make it more efficient come to your mind?
Here's a snipped from the most essential part of the code:
JASS:
function SaveInventory takes nothing returns nothing
local player p = GetTriggerPlayer()
local integer i = GetConvertedPlayerId(p)
local integer key = GetUnitUserData(udg_InventoryUnit[i])
if (udg_InvUnitPage[key] == 0) then
set udg_InvItemSlot1Page1[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 1))
set udg_InvItemSlot2Page1[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 2))
set udg_InvItemSlot3Page1[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 3))
set udg_InvItemSlot4Page1[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 4))
set udg_InvItemSlot5Page1[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 5))
set udg_InvItemSlot6Page1[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 6))
else
endif
if (udg_InvUnitPage[key] == 1) then
set udg_InvItemSlot1Page2[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 1))
set udg_InvItemSlot2Page2[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 2))
set udg_InvItemSlot3Page2[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 3))
set udg_InvItemSlot4Page2[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 4))
set udg_InvItemSlot5Page2[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 5))
set udg_InvItemSlot6Page2[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 6))
else
endif
if (udg_InvUnitPage[key] == 2) then
set udg_InvItemSlot1Page3[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 1))
set udg_InvItemSlot2Page3[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 2))
set udg_InvItemSlot3Page3[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 3))
set udg_InvItemSlot4Page3[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 4))
set udg_InvItemSlot5Page3[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 5))
set udg_InvItemSlot6Page3[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 6))
else
endif
if (udg_InvUnitPage[key] == 3) then
set udg_InvItemSlot1Page4[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 1))
set udg_InvItemSlot2Page4[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 2))
set udg_InvItemSlot3Page4[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 3))
set udg_InvItemSlot4Page4[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 4))
set udg_InvItemSlot5Page4[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 5))
set udg_InvItemSlot6Page4[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 6))
else
endif
if (udg_InvUnitPage[key] == 4) then
set udg_InvItemSlot1Page5[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 1))
set udg_InvItemSlot2Page5[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 2))
set udg_InvItemSlot3Page5[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 3))
set udg_InvItemSlot4Page5[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 4))
set udg_InvItemSlot5Page5[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 5))
set udg_InvItemSlot6Page5[key] = GetItemTypeId(UnitItemInSlotBJ(udg_InventoryUnit[i], 6))
else
endif
endfunction