W
Wardog
Guest
Good Morning,
So I've currently got a functioning inventory, that will be able to read from a large database of hundreds of items. However, each item could impact a number of player stats, and I'm curious if the inventory method I'm usually seeing online using data structures and enumerators is still the most efficient method for this.
ds_items_info = ds_grid_create(16, item.height);
This results in needing to create a very large database of items, using the structure below:
Then, should the mana potion be consumed, it impacts the player's stats in the following code:
As you can see from the code, the game modifies the player's current stats by checking every single possible stat of the item consumed, resulting in hundreds of lines of code where for some items, the game will check for a stat with a "0" value.
As such, I'm curious if the Mana Potion in the example above could be written as such:
Or, if the original method is the proper, most efficient way of doing this (performance-wise, I can understand needing coding to take longer to result in more efficient game performance), and I should press on with what I have.
So I've currently got a functioning inventory, that will be able to read from a large database of hundreds of items. However, each item could impact a number of player stats, and I'm curious if the inventory method I'm usually seeing online using data structures and enumerators is still the most efficient method for this.
ds_items_info = ds_grid_create(16, item.height);
// Item Database (ID #)
enum item {
none = 0,
mana potion = 1,
health potion = 2,
staff = 3,
cape = 4,
wizard hat = 5,
height = 6,
}
enum item {
none = 0,
mana potion = 1,
health potion = 2,
staff = 3,
cape = 4,
wizard hat = 5,
height = 6,
}
// Item ID # - Item Name
// Item Name = 0
// Item Description = 1
// Item Base Value = 2
// Item HP Restore = 3
// Item HP Regen = 4
// Item MP Restore = 5
// Item MP Regen = 6
// Item Move Speed = 7
// Item Damage = 8
// Item Attack Speed = 9
// Item Attack Range = 10
// Item Defense = 11
// Item Heat Resist = 12
// Item Cold Resist = 13
// Item Elec Resist = 14
// Item Poison Resist = 15
// Item Vision Range = 16
// Item Name = 0
// Item Description = 1
// Item Base Value = 2
// Item HP Restore = 3
// Item HP Regen = 4
// Item MP Restore = 5
// Item MP Regen = 6
// Item Move Speed = 7
// Item Damage = 8
// Item Attack Speed = 9
// Item Attack Range = 10
// Item Defense = 11
// Item Heat Resist = 12
// Item Cold Resist = 13
// Item Elec Resist = 14
// Item Poison Resist = 15
// Item Vision Range = 16
This results in needing to create a very large database of items, using the structure below:
// Item ID #0 - Nothing
ds_items_info[# 0, 0] = "Nothing";
ds_items_info[# 1, 0] = "Nothing";
ds_items_info[# 2, 0] = 0;
ds_items_info[# 3, 1] = 0;
ds_items_info[# 4, 1] = 0;
ds_items_info[# 5, 1] = 0;
ds_items_info[# 6, 1] = 0;
ds_items_info[# 7, 1] = 0;
ds_items_info[# 8, 1] = 0;
ds_items_info[# 9, 1] = 0;
ds_items_info[# 10, 1] = 0;
ds_items_info[# 11, 1] = 0;
ds_items_info[# 12, 1] = 0;
ds_items_info[# 13, 1] = 0;
ds_items_info[# 14, 1] = 0;
ds_items_info[# 15, 1] = 0;
ds_items_info[# 16, 1] = 0;
ds_items_info[# 0, 0] = "Nothing";
ds_items_info[# 1, 0] = "Nothing";
ds_items_info[# 2, 0] = 0;
ds_items_info[# 3, 1] = 0;
ds_items_info[# 4, 1] = 0;
ds_items_info[# 5, 1] = 0;
ds_items_info[# 6, 1] = 0;
ds_items_info[# 7, 1] = 0;
ds_items_info[# 8, 1] = 0;
ds_items_info[# 9, 1] = 0;
ds_items_info[# 10, 1] = 0;
ds_items_info[# 11, 1] = 0;
ds_items_info[# 12, 1] = 0;
ds_items_info[# 13, 1] = 0;
ds_items_info[# 14, 1] = 0;
ds_items_info[# 15, 1] = 0;
ds_items_info[# 16, 1] = 0;
// Item ID #1 - Mana Potion
ds_items_info[# 0, 1] = "Mana Potion";
ds_items_info[# 1, 1] = "You're not a wizard, Harry, the potions make you one.";
ds_items_info[# 2, 1] = 10;
ds_items_info[# 3, 1] = 0;
ds_items_info[# 4, 1] = 0;
ds_items_info[# 5, 1] = 50;
ds_items_info[# 6, 1] = 2;
ds_items_info[# 7, 1] = 0;
ds_items_info[# 8, 1] = 0;
ds_items_info[# 9, 1] = 0;
ds_items_info[# 10, 1] = 0;
ds_items_info[# 11, 1] = 0;
ds_items_info[# 12, 1] = 0;
ds_items_info[# 13, 1] = 0;
ds_items_info[# 14, 1] = 0;
ds_items_info[# 15, 1] = 0;
ds_items_info[# 16, 1] = 0;
ds_items_info[# 0, 1] = "Mana Potion";
ds_items_info[# 1, 1] = "You're not a wizard, Harry, the potions make you one.";
ds_items_info[# 2, 1] = 10;
ds_items_info[# 3, 1] = 0;
ds_items_info[# 4, 1] = 0;
ds_items_info[# 5, 1] = 50;
ds_items_info[# 6, 1] = 2;
ds_items_info[# 7, 1] = 0;
ds_items_info[# 8, 1] = 0;
ds_items_info[# 9, 1] = 0;
ds_items_info[# 10, 1] = 0;
ds_items_info[# 11, 1] = 0;
ds_items_info[# 12, 1] = 0;
ds_items_info[# 13, 1] = 0;
ds_items_info[# 14, 1] = 0;
ds_items_info[# 15, 1] = 0;
ds_items_info[# 16, 1] = 0;
Then, should the mana potion be consumed, it impacts the player's stats in the following code:
// Modification of Player Stats
obj_player_stats.currenthp += real(inv_info[# 3, item]);
obj_player_stats.hpregen += real(inv_info[# 4, item]);
obj_player_stats.currentmp += real(inv_info[# 5, item]);
obj_player_stats.mpregen += real(inv_info[# 6, item]);
obj_player_stats.spd += real(inv_info[# 7, item]);
obj_player_stats.damage += real(inv_info[# 8, item]);
obj_player_stats.atkspeed += real(inv_info[# 9, item]);
obj_player_stats.atkrange += real(inv_info[# 10, item]);
obj_player_stats.defense += real(inv_info[# 11, item]);
obj_player_stats.heatresist += real(inv_info[# 12, item]);
obj_player_stats.coldresist += real(inv_info[# 13, item]);
obj_player_stats.elecresist += real(inv_info[# 14, item]);
obj_player_stats.poisonresist += real(inv_info[# 15, item]);
obj_player_stats.visionrange += real(inv_info[# 16, item]);
obj_player_stats.currenthp += real(inv_info[# 3, item]);
obj_player_stats.hpregen += real(inv_info[# 4, item]);
obj_player_stats.currentmp += real(inv_info[# 5, item]);
obj_player_stats.mpregen += real(inv_info[# 6, item]);
obj_player_stats.spd += real(inv_info[# 7, item]);
obj_player_stats.damage += real(inv_info[# 8, item]);
obj_player_stats.atkspeed += real(inv_info[# 9, item]);
obj_player_stats.atkrange += real(inv_info[# 10, item]);
obj_player_stats.defense += real(inv_info[# 11, item]);
obj_player_stats.heatresist += real(inv_info[# 12, item]);
obj_player_stats.coldresist += real(inv_info[# 13, item]);
obj_player_stats.elecresist += real(inv_info[# 14, item]);
obj_player_stats.poisonresist += real(inv_info[# 15, item]);
obj_player_stats.visionrange += real(inv_info[# 16, item]);
As you can see from the code, the game modifies the player's current stats by checking every single possible stat of the item consumed, resulting in hundreds of lines of code where for some items, the game will check for a stat with a "0" value.
As such, I'm curious if the Mana Potion in the example above could be written as such:
// Item ID #1 - Mana Potion
ds_items_info[# 0, 1] = "Mana Potion";
ds_items_info[# 1, 1] = "You're not a wizard, Harry, the potions make you one.";
ds_items_info[# 2, 1] = 10;
ds_items_info[# 5, 1] = 50;
ds_items_info[# 6, 1] = 2;
ds_items_info[# 0, 1] = "Mana Potion";
ds_items_info[# 1, 1] = "You're not a wizard, Harry, the potions make you one.";
ds_items_info[# 2, 1] = 10;
ds_items_info[# 5, 1] = 50;
ds_items_info[# 6, 1] = 2;
Or, if the original method is the proper, most efficient way of doing this (performance-wise, I can understand needing coding to take longer to result in more efficient game performance), and I should press on with what I have.