I think the reason you think using the actor would be less complicated would be the mouse button down differentiation. If that is the case, I explain what to do thoroughly in the following.
Global Code->global
- Code: Select all
#define MAX 24
int itemtype[MAX];
int row;
int ActionNum;
Okay, I commented these within the demo but I'll expound on their functions. These are the only global variables. The #define now sets the word MAX to equal 24. This demo has a limited inventory of 24. To increase the amount of items it can hold, you should increase the 24 by multiples of 8.
itemtype is an int array. If you don't know what an array is, it is essentially [x] number of ints, in this case MAX number (24). Each int is an inventory spot, the number represents what item. 0=empty, 1=Item1, 2=Item2, and so on
row is an int that determines which set of 8 you are displaying. While row equals 0, the inventory display actors show 0-7, while row equal 1, they display 8-15, and so on.
ActionNum is what you are going to do. While it equals 0, you cannot do anything, If it equals 1, you can put things into your inventory. If it equals 2, you can use items in the inventory, in this demo using items destroys them.
Global Code->ofst
- Code: Select all
int
ofst (int r, int c)
{
return (r*8+c);
}
Okay, this function is used to retrieve certain spots in the itemtype[]. When given row and column, it will give back a single int that corresponds to whichever inventory spot is in row r, column c. This is used frequently, especially by the itemDisplay actors.
Item->MouseButtonDown(left)->Script Editor
- Code: Select all
int i;
int item = 1;
switch(ActionNum)
{
case 0:
break;
case 1:
for(i=0; i<MAX; i++)
{
if(itemtype[i]==0)
{
if(i%8==0 && i!=0)
{
row++;
}
itemtype[i]=item;
DestroyActor("Event Actor");
break;
}
}
ActionNum=0;
break;
case 2:
break;
}
This is a big one to understand. i is initialized which will be used for a loop that searches where to place the item. The int item is also important to get right. You can copy/paste this into each items mbd event. For each one, item needs to equal a different value. This value is very important, as it is what goes into the itemtype, signifying to the itemDisplay actors which item to show.
Next is the switch(ActionNum), if you don't know how switches work, here is a simple switch.
- Code: Select all
switch(variable)
{
case 0: // when the switch is run if variable==0
// code until break, then exit the switch
break;
case 1: // else if variable==1, run code until break the exit switch
break;
}
You can create as many cases as you wish, you will need one for every item. The only case with code within it is case 1, which is if you have selected pickup. When you click the item, it looks for the first available itemtype[]. (first that is equal to zero) It searches through all, excecuting when that itemtype[] is zero, but it breaks, exiting the for loop. The next bit if(i%8==0 && i!=0) checks if the next spot is the eighth spot in the row. If so, go to the next row, so you can see the new item. Now, it sets the itemtype[], or inventory spot, to whatever the item is. Afterwards, it gets rid of the action type, setting it to nothing, 0.
itemDisplay->DrawActor->Script Editor
- Code: Select all
int i;
switch(itemtype[ofst(row,cloneindex)])
{
case 0:
for(i=ofst(row,cloneindex); i<MAX; i++)
{
if(itemtype[i]>0)
{
itemtype[ofst(row,cloneindex)]=itemtype[i];
itemtype[i]=0;
break;
}
}
break;
}
animpos=itemtype[ofst(row,cloneindex)];
i again is used for a loop, this loop is used to slide items so that all item spots are being used, or all are in front/lower spots.The switch statement determines what itemtype is in it. In the case of 0, nothing in it, the square checks if it can slide an item down, and the spot. It then changes its animpos to fit the item.
-Note that the previous demo changed the animation, instead of animpos=. This is more efficient and easier to understand. I kept the switch statement, because it is good to get in the habit of avoiding unnecessary ifs. In this case it doesn't really matter.
-Also, the animation for itemDisplay must correlate with the item numbers. Just add more animations to the bottom of the itemDisplay.png, then edit the animation within gE, and set the frames to the right amount.
-This way also gets rid of the little flash when you use an item.
itemDisplay->MouseButtonDown(Left)->Script Editor
- Code: Select all
switch(ActionNum)
{
case 0:
break;
case 1:
break;
case 2:
switch(itemtype[ofst(row,cloneindex)])
{
case 1:
itemtype[ofst(row,cloneindex)]=0;
break;
case 2:
itemtype[ofst(row,cloneindex)]=0;
break;
}
ActionNum=0;
break;
}
This uses the same structure as the item's mbd event, except the code is in case 2, the use ActionNum. Inside is another case, determining what to do pending on what item is there. In both case 1 and 2, the item does not actually do anything, it just disappears. You would insert your item's use there.
The rest is pretty much the same concept, such as the text display, that code is within the mouse enter event of the itemDisplay actors. Change the item name description to what you wish. I believe that covers it, if not feel free to ask any questions.
If this really is too complex, I could work on an easier one that uses the moving of actors, but I would need a bit of time to format it in a way that it is less complex. I don't think you'll need it though, if you understand the concepts I used, I think you can understand the actual goings on of this demo.