H
Halas
Guest
Hello,
Ever since the 2.3 update, I have been dealing with some issues regarding id and data structures.
When I equip an item, it reads the stats on the item and then transfers that data to the character stats.
This block of code identifies what item is picked up and which stats need to be applied.
Once the correct Stats roll is selected, this script runs:
I notice this entire block of code is not currently running completely.
Two scripts that I have identified that are causing the issue:
Previous to 2.3 Subscribe would collect the "id" of the object, and unsubscribe would also use "id"
If I use "id" I get this error:
but removing "id" gets rid of this error but still causes issues in the code. I have since changed it to I use "_i" to try and specify the specific item to unsubscribe, but i do not believe it works properly as items no long register properly.
Ever since the 2.3 update, I have been dealing with some issues regarding id and data structures.
When I equip an item, it reads the stats on the item and then transfers that data to the character stats.
This block of code identifies what item is picked up and which stats need to be applied.
GML:
//Update Stats
if ex_item_get_amount(_pressed_slot.inv,_pressed_slot.index) >= 1
{
var _item = _pressed_slot.item[? "category"]
show_debug_message(string(_item))
//Items
if _item = "spell"
{
ex_ev_subscribe(global.inv_equipment, id, Spells_roll)
show_debug_message("Spells Roll")
}
if _item != "spell" && _item != "rune"
{
ex_ev_subscribe(global.inv_equipment, id, Stats_roll)
show_debug_message("Stats Roll")
}
if _item = "rune"
{
ex_ev_subscribe(global.inv_runespage, id, Runes_roll)
show_debug_message("Runes Roll")
}
}
Once the correct Stats roll is selected, this script runs:
I notice this entire block of code is not currently running completely.
Code:
function Stats_roll()
{
var _inv = global.inv_equipment;
show_debug_message("Stats Roll Script")
for (var a=0; a<5; a++)
{
global.Stats[a] -= global.stats_items[a];
global.stats_items[a] = 0;
Obj_Player.weapon = 0;
Obj_Player.Idmg = 0;
}
//Check item and its Stats
for (var _i = 0; _i < ex_inv_max_size(_inv); _i++)
{
if (ex_item_get_amount(_inv, _i)) >= 1
{
//Get Info
var _key = ex_tag_get(_inv,_i,"Key");
var _istat = ex_tag_get(_inv, _i, "Istat");
var _ivalue = ex_tag_get(_inv, _i, "Ivalue");
if is_undefined(_ivalue) { return 0;};
var _idmg = ex_tag_get(_inv, _i, "Damage");
global.stats_items[_istat] += _ivalue;
Obj_Player.Idmg = _idmg
Obj_Player.weapon = _key
ex_ev_unsubscribe(_inv, _i);
}
}
//Add Item Stats to Player Stats
for (var a=0; a<5; a++)
{
global.Stats[a] += global.stats_items[a]
}
}
Two scripts that I have identified that are causing the issue:
Previous to 2.3 Subscribe would collect the "id" of the object, and unsubscribe would also use "id"
If I use "id" I get this error:
___________________________________________
############################################################################################
ERROR in
action number 1
of Other Event: User Defined 2
for object obj_inv_panel:
Data structure with index does not exist.
at gml_Object_obj_inv_panel_Other_12 (line 28) - var _item = _pressed_slot.item[? "category"]
############################################################################################
gml_Object_obj_inv_panel_Other_12 (line 28)
gml_Object_obj_inv_panel_equipment_Other_12 (line 57)
gml_Object_obj_inv_mouse_Step_0 (line 9)
############################################################################################
ERROR in
action number 1
of Other Event: User Defined 2
for object obj_inv_panel:
Data structure with index does not exist.
at gml_Object_obj_inv_panel_Other_12 (line 28) - var _item = _pressed_slot.item[? "category"]
############################################################################################
gml_Object_obj_inv_panel_Other_12 (line 28)
gml_Object_obj_inv_panel_equipment_Other_12 (line 57)
gml_Object_obj_inv_mouse_Step_0 (line 9)
Code:
function ex_ev_subscribe(_inv, _instance, _script)
{
//var _inv = argument0;
//var _instance = argument1;
//var _script = argument2;
//get list of subscribers for this event
var _observers = _inv[? "observers"];
//create observer array
var _observer = array_create(2);
//add instance
_observer[0] = _instance;
//add script
_observer[1] = _script;
//register
ds_list_add(_observers, _observer);
}
Code:
function ex_ev_unsubscribe(_inv, _instance) {
//var _inv = argument0;
//var _instance = argument1;
//get list of subscribers for this event
var _observers = _inv[? "observers"];
//remove from the subscribers
var _observers_count = ds_list_size(_observers);
for(var _i = _observers_count - 1; _i >= 0; _i--) {
var _observer = _observers[| _i];
if(_observer[0] == _instance) {
ds_list_delete(_observers, _i);
}
}
}