Jump to content


Photo

Help with item inventory


  • Please log in to reply
4 replies to this topic

#1 batlord

batlord

    GMC Member

  • GMC Member
  • 130 posts

Posted 19 January 2011 - 03:08 PM

Hello I am working on a mouse controlled RPG Game which contains items inventory all what I wanna do is when you press the button to show the inventory with it's items and when I press it to hide it with it's items.

However, no matter how many items I put it only shows the last one , why??

Here is my codes

In objPlayer Create event:
item[10] = object0; // ==> object0 is the default "instead of null in other languages"

current_index = 0; // ==> used to check which index shall get the item
current_y_item = 32 //to order the inventory

for (i = 0; i <= 10; i+=1)
{
  item[i] = object1; // ==> to make sure that all indexes have an object value
}

In objDragged Left Release event >> it's used to drag the items onto the inventory and it stays on the mouse
instance_create(500,objPlayer.current_y_item,objItem);
objPlyaer.item[objPlyaer.current_index] = objItem; 
objPlyaer.current_index += 1;
objPlayer.current_y_item += 33;


In objItem Destroy Event
objPlyaer.current_index -= 1;
objPlayer.current_y_item -= 33;

in objShowInventoryButton Left Pressed Event
for (i=0;i<=10;i+=1)
{
  with(objPlayer)
  {
    if (item[other.i] != object0)
    {
      instance_create(520,(33*i)+2,obj_item);
    }
  }
}

But in the debugging it shows instance_number(objItem) is 0 And it only creates one objItem at x=520 and y=2
  • 0

#2 FoxInABox

FoxInABox

    GMC Member

  • GMC Member
  • 5379 posts
  • Version:GM:Studio

Posted 19 January 2011 - 04:06 PM

both should be other.i , so you have been creating all the items at the same spot:

objShowInventoryButton Left Pressed Event
... item[other.i] ... ,(33*i)+2,

alternative ones:
for (i=0;i<=10;i+=1)
  if (objPlayer.item[i] != object0)
    instance_create(520,(33*i)+2,obj_item);

var i; // usefull if you don't want to add other when going between diffrent instances
for (i=0;i<=10;i+=1)
  with(objPlayer)
    if (item[i] != object0)
      instance_create(520,(33*i)+2,obj_item);

I don't see the point of having current_y_item since you could multiply current_index with 33 (+32)

I would have used the value "noone" instead of a object ^^

and if you can move items in the inventory, then I would have removed current_item aswell, and instead just looped thru it and found the first free spot:

with(player){
  for(i=0;i<=10;i+=1) if item[i]=object0 break;

  if i!=11 { // if it broke the loop before it reached the value 11
    // then it found a empty slot, place item

    instance_create(500,(33*i)+2,objItem);
    item[i] = objItem; 
  }
}

  • 0

#3 batlord

batlord

    GMC Member

  • GMC Member
  • 130 posts

Posted 19 January 2011 - 04:50 PM

both should be other.i , so you have been creating all the items at the same spot:

objShowInventoryButton Left Pressed Event

... item[other.i] ... ,(33*i)+2,

alternative ones:
for (i=0;i<=10;i+=1)
  if (objPlayer.item[i] != object0)
    instance_create(520,(33*i)+2,obj_item);

var i; // usefull if you don't want to add other when going between diffrent instances
for (i=0;i<=10;i+=1)
  with(objPlayer)
    if (item[i] != object0)
      instance_create(520,(33*i)+2,obj_item);

I don't see the point of having current_y_item since you could multiply current_index with 33 (+32)

I would have used the value "noone" instead of a object ^^

and if you can move items in the inventory, then I would have removed current_item aswell, and instead just looped thru it and found the first free spot:

with(player){
  for(i=0;i<=10;i+=1) if item[i]=object0 break;

  if i!=11 { // if it broke the loop before it reached the value 11
    // then it found a empty slot, place item

    instance_create(500,(33*i)+2,objItem);
    item[i] = objItem; 
  }
}


sorry by bad the code in objShowInventoryButton Left Pressed Event
for (i=0;i<=10;i+=1)
{
  with(objPlayer)
  {
    if (item[other.i] != object0)
    {
      instance_create(520,(33*i)+2,item[other.i]);
    }
  }
}

  • 0

#4 FoxInABox

FoxInABox

    GMC Member

  • GMC Member
  • 5379 posts
  • Version:GM:Studio

Posted 19 January 2011 - 05:18 PM

you didn't fix the "i" by adding other where I mentioned, maybe if I highlight it better:
instance_create(520,(33*other.i)+2,item[other.i]);

i recomand using "i" as an var variable, for some cases like this, that way you don't have to get an ownership problem when visiting multible instances.. but aslong as you remember to write other. where it it needed should it be okay.
  • 0

#5 batlord

batlord

    GMC Member

  • GMC Member
  • 130 posts

Posted 21 January 2011 - 09:24 PM

Ok Thnx
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users