Pandamine created a really good system for retrieving handle data for structs, and being able to move them from function to function without ever touching a gamecache
I was fascinated because I love globals, and using something very very similar to a struct, can utilize the system without ever needing JassNewGen!!!
But, since the system was set up for structs, which are specially made, I thought I might get some problems
Basically, I revised the system a bit, and when it loops through all of the data in the 3 variable arrays (which doing it the way I am, should be quickly with maps that have physics in them) will loop back to the beginning and start all over again, making the DataSystem useable no matter how long you play the game
Please Note, I improved it for regular Jass, so the "globals" block is what you need to put up in the udg variables
I was fascinated because I love globals, and using something very very similar to a struct, can utilize the system without ever needing JassNewGen!!!
But, since the system was set up for structs, which are specially made, I thought I might get some problems
Basically, I revised the system a bit, and when it loops through all of the data in the 3 variable arrays (which doing it the way I am, should be quickly with maps that have physics in them) will loop back to the beginning and start all over again, making the DataSystem useable no matter how long you play the game
Please Note, I improved it for regular Jass, so the "globals" block is what you need to put up in the udg variables
JASS:
//globals
// integer array udg_Data1
// integer array udg_Data2
// integer array udg_Data3
// integer udg_LoopData = 0
//endglobals
//*Thanks to Pandamine for the Data Template
//*Modified so that the index will loop back from the start of the arrays when
//it has progressed past the third (not being used in conjuncture with structs)
function DS_H2I takes handle h returns integer
return h
return 0
endfunction
function SetData takes handle h, integer v returns nothing
local integer i = DS_H2I(h) - 0x100000
set i = i - 24573 * udg_LoopData
if (i < 8191) then
set udg_Data1[i] = v
elseif (i < 16382) then
set udg_Data2[i - 8191] = v
elseif (i < 24573) then
set udg_Data3[i - 16382] = v
else
call BJDebugMsg("Data System Error: SetData handle index too high")
set udg_LoopData = udg_LoopData + 1 //Will loop back, and then reset the data
call SetData(h , v) //Loop will allow data to continue to be used
endif
endfunction
function GetData takes handle h returns integer
local integer i = DS_H2I(h) - 0x100000
//Needed to drop down 1, because of zero (>= 24573, is also > 24572)
if i > 24572 * udg_LoopData then //If your getting data stored for an extended period of time
set i = i - 24573 * udg_LoopData //This if/then will check and retrieve the appropriate data
endif
if (i < 8191) then
return udg_Data1[i]
elseif (i < 16382) then
return udg_Data2[i - 8191]
elseif (i >= 24573) then
//call BJDebugMsg("Data System Error: GetData handle index too high") would be annoying to have for the last array
endif
return udg_Data3[i - 16382]
endfunction