array problem can I have array[x].smth?

S

SeMike

Guest
Hi guys I watned to ask you
Im doing items and I would like to ask you If I can do
item_slot[n].sprite or .smth?
Thank you
 

Bingdom

Googledom
I may be wrong on this... Please correct me if im wrong ;)
Using '.' is referencing from an object, you would use it something like this
Code:
if OBJ_Player.hp <= 0 {
     with(OBJ_Player) {
          instance_destroy();
     }
}
or this
Code:
enemy = other.id
if enemy.hp <= 0 {
    with(enemy) instance_destroy();
}
The way you should use arrays is something like this.
Code:
item_slot[0] = SPR_Gun;
item_slot[1] = SPR_Ammo;
item_slot[2] = SPR_HealthPotion;
item_slot[3] = SPR_Food;
 
A

Aura

Guest
You can do that as long as item_slot[n] holds a valid object index or an instance ID whose correspoing instance exists at the time of code execution. Read more about it here:

http://docs.yoyogames.com/source/da..._gml language overview/401_05_addressing.html

But I guess you want to look into 2D arrays whose first dimension would represent the item and second dimension(s) would hold information related to that item. For instance:

Code:
item_slot[0, 0] = "Sword"; //Name of the item
item_slot[0, 1] = spr_sword;
What are you trying to do anyway?
 
S

SeMike

Guest
Ïnventory system and draw inventory
Code:
if(inv=1){ // ZOBRAZIT INVENTAR (NON-EQUPIED ITEMS)
n=0
repeat(inventory_slots)
{
if(inv_slot[n]=0) then item_sprite=spr_free_item_slot else item_sprite=inv_slot[n].spr;
draw_sprite(item_sprite,0,view_xview+520+32*n+2,view_yview+450)
n+=1
}
}
and my actual problem is.. if the inv_slot[n] (its object_weapon1 or whatever) isnt somewhere in the room on the floor it just shows error but it normally works if the item is somewhere randomly in the room used.. If I could fix that my inventory system would work great^^
 
S

SeMike

Guest
nevermind im doing the inventory system othert way cuz since i was only drawing sprites there wouldnt be a possibility to click on em or smth.. my bad :D few hours of life lost XD np atlest I learn^^ but ty for ur advices boyyz
 
Top