inventoryInteraction,
startOfTurn,
endOfTurn,
onHurt,
onUseItem,
onPickUpInInventory
}
function item(_name,_sprite,_useFunction,_useTrigger,_description,_types,_space) constructor{
name=_name
sprite=_sprite
useFunction=_useFunction
useTrigger=_useTrigger
space=_space
types=_types
description=_description
function New(){
var _struct={}
var _names=struct_get_names(self)
for(var i=0;i<array_length(_names);i++)
{
variable_struct_set(_struct,_names[i],variable_struct_get(self,_names[i]))
}
}
}
function add_item(_name,_sprite,_useFunction,_useTrigger,_description,_types=[0],_space=new vector2(1,1)){
var _item=new item(_name,_sprite,_useFunction,_useTrigger,_description,_types,_space)
array_push(global.itemList,_item)
}
function standard_attack(){
for(var i=0;i<4;i++)
{
if(collision_line(position.x,position.y,position.x+lengthdir_x(GRID_SIZE,i*90),position.y+lengthdir_y(GRID_SIZE,i*90),obj_enemy_parent,true,true))
{
}
}
}
global.itemTypes=ds_map_create()
ds_map_add(global.itemTypes,0,"Material")
ds_map_add(global.itemTypes,1,"Weapon")
ds_map_add(global.itemTypes,2,"Wooden")
ds_map_add(global.itemTypes,3,"Consumable")
ds_map_add(global.itemTypes,4,"Potion")
ds_map_add(global.itemTypes,5,"Armor")
ds_map_add(global.itemTypes,6,"Magic")
global.itemList=[]
add_item("Stripped Bark",spr_stripped_bark,standard_attack,useTriggers.inventoryInteraction,"A sharp piece of bark stripped from a tree. Deals 2 damage to enemies in front of you.",[1,2],new vector2(1,2))```|
i have all of this code running in a script but for osme reason it says that `global.itemList` isn't set before reading when i'm pretty sure it is. is there anything i'm missing here?
#global variable not set before reading when it is set?
17 messages · Page 1 of 1 (latest)
here's the error:
global variable name 'itemList' index (100031) not set before reading it.
at gml_Script_add_item (line 33) - array_push(global.itemList,_item)
############################################################################################
gml_Script_add_item (line 33)
gml_GlobalScript_enemies (line 33) - add_item("Stripped Bark",spr_stripped_bark,standard_attack,useTriggers.inventoryInteraction,[1,2],new vector2(1,2))
Try declaring it before the function that uses it
did that, that didn't fix the problem ```function item(_name,_sprite,_useFunction,_useTrigger,_description,_types,_space) constructor{
name=_name
sprite=_sprite
useFunction=_useFunction
useTrigger=_useTrigger
space=_space
types=_types
description=_description
function New(){
var _struct={}
var _names=struct_get_names(self)
for(var i=0;i<array_length(_names);i++)
{
variable_struct_set(_struct,_names[i],variable_struct_get(self,_names[i]))
}
}
}
global.itemList=[]
function add_item(_name,_sprite,_useFunction,_useTrigger,_description,_types=[0],_space=new vector2(1,1)){
var _item=new item(_name,_sprite,_useFunction,_useTrigger,_description,_types,_space)
array_push(global.itemList,_item)
}
function standard_attack(){
for(var i=0;i<4;i++)
{
if(collision_line(position.x,position.y,position.x+lengthdir_x(GRID_SIZE,i90),position.y+lengthdir_y(GRID_SIZE,i90),obj_enemy_parent,true,true))
{
}
}
}
global.itemTypes=ds_map_create()
ds_map_add(global.itemTypes,0,"Material")
ds_map_add(global.itemTypes,1,"Weapon")
ds_map_add(global.itemTypes,2,"Wooden")
ds_map_add(global.itemTypes,3,"Consumable")
ds_map_add(global.itemTypes,4,"Potion")
ds_map_add(global.itemTypes,5,"Armor")
ds_map_add(global.itemTypes,6,"Magic")
add_item("Stripped Bark",spr_stripped_bark,standard_attack,useTriggers.inventoryInteraction,"A sharp piece of bark stripped from a tree. Deals 2 damage to enemies in front of you.",[1,2],new vector2(1,2))```
i have literally never had this problem before
Same error as before?
What's in the vector constructor?
The error could maybe be that you're using keywords (e.g. x, sprite_index), inside of the script and it's trying to reach those variables from vector?
x=_x
y=_y
function equals(_vec){
if(x==_vec.x&&y==_vec.y)
{
return true
}
return false
}
}```
that's all there is
Try commenting out what's in vector2 and try running, like I've mentioned it could be a script trying to access positional keywords that it doesn't own
ok that actually fixed it
is it maybe because the script that adds vector 2 runs after the items script?
I think it's because scripts don't have access to keywords like x and y, it's not an object, so when you call them and set them in scripts like that you run into problems
yeah the problem was the vector 2 script running after the items script
i put vector 2 at the top of the items script and it works