D
Daniel Cook
Guest
Hey guys,
I'm working on a project item system and I was hoping for a bit of guidence regaruding the best practice to storing large amounts of data. The set-up is this:
I have numour item within my game, lets say 100 for now.
Each of though items holds 10 variables with different values.
I have used an Enum to give each of my items a uniqe IDNumber.
Now when I want to create a new item I have come up with 2 ways of doing this.
The first (which in my mind is the better way), is to have a script which takes the ID number as an argument and then uses a Switch function to assign the correct values to a new instance.
var _itemID = argument0;
var _inst = instanceCreate();
switch(_itemID){
return _inst;
The second, is to have a global instance holding all of the data in arrays. So within a script I would do this.
var _itemID = argument0;
var _inst = instanceCreate();
var _index = global.itemData_inst;
I have a limited understanding of how computer alocate memory, but from what I understand. If i go with option 2, then a chucnk of memory would be assigned for all 10 variable for all 100 items. So it is holding 1000 variables all the time for something that I only needs to call on maybe 2 times every minute.
While option 1 would mean that the data isn't stored perminently, but only for the step when the script is called. It would also only store the 10 variable within the relivent Case Block, as oposed to all 1000 variables at all times.
Is my thinking correct or am I was off the mark.
Thank for reading I know its a long 1.
I'm working on a project item system and I was hoping for a bit of guidence regaruding the best practice to storing large amounts of data. The set-up is this:
I have numour item within my game, lets say 100 for now.
Each of though items holds 10 variables with different values.
I have used an Enum to give each of my items a uniqe IDNumber.
Now when I want to create a new item I have come up with 2 ways of doing this.
The first (which in my mind is the better way), is to have a script which takes the ID number as an argument and then uses a Switch function to assign the correct values to a new instance.
var _itemID = argument0;
var _inst = instanceCreate();
switch(_itemID){
case itemIndex.gun:
}_inst.var1 = 10;
_inst.var2 = 2;
...
break;
case itemIndex.sword:_inst.var2 = 2;
...
break;
_inst.var1 = 2;
_inst.var2 = 54;
...
break;
..._inst.var2 = 54;
...
break;
return _inst;
The second, is to have a global instance holding all of the data in arrays. So within a script I would do this.
var _itemID = argument0;
var _inst = instanceCreate();
var _index = global.itemData_inst;
inst.var1 = _index.array1[_itemID];
inst.var2 = _index.array2[_itemID];
...
return _inst;inst.var2 = _index.array2[_itemID];
...
I have a limited understanding of how computer alocate memory, but from what I understand. If i go with option 2, then a chucnk of memory would be assigned for all 10 variable for all 100 items. So it is holding 1000 variables all the time for something that I only needs to call on maybe 2 times every minute.
While option 1 would mean that the data isn't stored perminently, but only for the step when the script is called. It would also only store the 10 variable within the relivent Case Block, as oposed to all 1000 variables at all times.
Is my thinking correct or am I was off the mark.
Thank for reading I know its a long 1.