Hey guys, haven't been on for a while and thought it be good to continue from where I left off on the Inventory for Max Proof. The great news is we fine tuned the Inventory and everything is working smoothly! After we completed the inventory we did some refactoring and took out anything we felt was unnecessary. Sadly considering this project is under development for mobile, we decided to remove the "
HoverBtn" function. To give an idea of what
HoverBtn was about, well the purpose of the function was to dynamically change the mouse cursors image when the player hovers over an inventory item or even a hazard in the scene. Having said that I wanted to go over the neat features we added on to the Inventory.
To break it down, we added in the feature of quantity..So whenever the user touches or clicks a button, depending on the item in the inventory, a deduction in quantity will occur. Upon quantity of an item being zero, we changed the graphic to the same graphic but with an X to indicate that hey...You probably can't use this item now. We as well made it that upon quantity being zero, all other logic for that specific item would not work. Considering this, we created a few getters and setters. But before I get to ahead of myself we need to graphically input quantity into the inventory.
Jumping to the
design view of our HUD blueprint I created
four text box's having them overlap each button individually. Each text box I named them accordingly to its designated item such as;
BoardQuantity, TapeQuantity, LockQuantity and GateQuantity. After doing so in
Content > Text I hit
create binding for each of them. The point of doing this is to well...Bind a function to the text. The function I want to bind is a kind of function that will practically know what the text should be and how it behaves. What great way to use getters and setters! So in other words the function i'm creating that's going to be binded to this text is a getter function.
To make my life simple since I know we will have four getters due to four items in the inventory, i'm going to need four integer variables that hold a value for the text;
CurrentQuantityB, CurrentQuantityT, CurrentQuantityL and CurrentQuantityG with each
default value of five. After creating the bind for the first item; board, I had the function basically
return a text of CurrentQuantityB. After doing that I continued the process of binding for the other three items.
Once completing the binding for each item in the inventory I begun creating the setters. The point of the setters for quantity is to well...Deduct. So when the function calls do
CurrentQuantity -= 1; Now after doing this I ran into the situation where yea my logic works but for some reason every now and then when I grabbed an item from the inventory it would just decrement to the negatives which was weird. So I basically hard coded it to make sure it remains zero once reaching zero. In the setter function that I created for the Board I basically said, set the
CurrentQuantityB -= 1 and if
CurrentQuantityB equals zero, set it to zero. Having done this resolved the issue preventing the quantity from continuously decrementing when it shouldn't be. After doing this I continued this same logic for the other items in the Inventory. Thus ending the quantity logic.
But wait, similar to the drop item function if we were to play the game you would see nothing from quantity. Reasoning why is because we
never implemented it in the Event Graph. Jumping to the Event Graph we ended up fine tuning some of the logic on the events
OnClicked. For
OnClicked(IS0) we previously saw,
on click > DropItem and thats it. Now for each of these events there's more logic that helps polish the inventory further. Since we implement a timer in the game we begin by checking hey if
isTime0 false then do this;
set BoardBtnClick to true then check
if CurrentQuantityB is equal to zero.
If False continue the logic;
Drop Item and then set BoardBtnClick to false. Now your probably wondering whats with the bool statement with time and where did
BoardBtnClick come from. To answer the question if that was a thought well...
BoardBtnClick is a bool variable I created. The purpose of this variable is to check when the button has and has not been clicked. If it has been set to true, then use the setter function we created. Unfortunately, I won't be going over our timer functionality because I don't want to take credit from my partners work but I will say he did a fantastic job! To get back on topic I continued this logic for the other four buttons.
To dive in further so we can actually get the quantity running when playing the game I added on into our drop item function. Inside the function I added a few more if statements.
If BoardBtnClick is true; use it's setter...If false check if GateBtnClick is true; use it's setter and continue on with the other two items. Having create this logic, when running the game the quantity works now...Which is awesome!
All that's left to completely end the Inventory is a few things that need to be added into our game loop. In our game loop we currently have it where we can dynamically set the mouse's position as well as the actors position. On top of that we can drop the item anytime we want. So what are we missing? Well originally when I created the logic for the game loop I had it when we click the item. Keep in mind the primary development of this game is to have it set to mobile. Having said that we need to add logic in that also checks when the user touches it using a smartphone. In the logic where we check
Is Input Key Down > Left mouse Button. We added an
OR operator to the Boolean statement. So if
Input Key Down > Left mouse Button OR Input Key Down > Touch 1. This will allow us to check for both PC and Smartphone. To continue our loop logic we needed to consider our timer. We don't want the player to grab items in the inventory while the timer is equal to zero. To prevent this from happening in the beginning of the loop we added a if statement.
If isTime0 is true, destroy actor > Target Actor. If False; continue the logic.
Now you may have notice from the image above that there's another function by the name of
MouseOverVolume. The way we wanted this game to work was to allow the user to only drop inventory items at specific locations. The purpose of MouseOverVolume is to do that. In the function MouseOverVolume we check a hit result. If the mouse cursor (considering the actor follows the mouse position) hits
any object type of destructible, set a new variable called
Collided to true.
Otherwise set it to false. Now you may be wondering why did I choose destructible? Well in the list of arrays to choose from, we had no option of only grabbing actors or specific actors. Considering we're not planning on creating a fracture meshes or anything like that, why not make our actors more specific by saying their destructible.
So now looking at our Event graph, at every tick we call this function. Since we added this function we also need to do another check.
If we have Collided, then now we are able to drop the item, if we choose to not drop it then continue calculating the mouse position and setting it to the actor position. If we were to play the game now everything is practically working as it should. We can grab the item in the inventory, drop it at a specific location as well as see that quantity on a item is being deducted. This concludes the majority of the inventory functionality. All that's left is creating logic that swaps out the graphic of the inventory item when quantity is zero. That part I will go over in a future blog!