Hello! i have made it a challenge to myself to create a full survival game using only blueprint visual scripting. i have almost finished the inventory system for my character. an issue i am having is when i press on say a food item at the bottom of the inventory window it shows info about the item and then if u press the Eat button it should give u the hunger value and then delete the item at its current index. what actually happens is it does everything correctly except it removes the first index even if it is another type of item. i cannot get it to remove any other index than the first one. and i really do not want to make it move an item when u select it to the first slot every time. that would get annoying. lol. any help would be awesome! thank you in advance!
Unity Engine 4.4.0
Hey -
It’s difficult to say what would be your best course of action. Could you post a screenshot of your blueprint for me to take a look at?
Thank you for the reply! i will show u a small portion but i do not mind showing you more if u need to :). both images will be under the Event Receive Hit Box Click.
Here i am setting LastInventorySlotSelected so that i can use it to remove the item from the array at its correct index.
In the second photo after i click on the “Eat” button it adds the food amout to hunger and then it should remove from the index saved in LastInventorySlotSelected.
The hit box names are saved the coresponding array index so they are the same 0 - 49. and i as u can see jLastInventorySlotSelected only get set if hitbox name is >= 0 so it should only save 0 - 49. but when i select “Eat” button it always removes index 0. even if the item in the array is of a diff item type.
Any help is Appreciated! I hope this is enough information!
Hi ,
Are you sure jLastInventorySlotSelected is being set to the proper index? I would recommend using [breakpoints][1] to verify that the value is being set from your cast nodes, otherwise the default value will be used (which is probably 0, and possibly the reason why the first element is being removed).
You can add breakpoints by selecting any node with an execute pin and and hitting F9. Then, when you simulate or play the game, the game will pause when the breakpoint is hit and you can inspect values that are being [watched][2].
Thank you for reply! Yes teh variable LastInventorySlotSelected is being set when i select and inventory item but it seems that once i hit the Eat button it sets it back to the default 0 since it does not = 0-49 for the button name it seems to default back to 0 even tho i have a branch before setting LastInventorySlotSelected with condition if (boxname >= 0) as shone in the image above.
The only thing i can think of is doing a switch on Name variable make 0-49 pins and have the default be 99 so if anything no slot will be deleted. but im not sure if this is a good way to go. i dont want to do anything in a way that could slow down the game during play.
Okay i tried making a function that has a Switch on Name and make pins for 0-49. then set the variable == the pin value (i.e. 0 = 0, 1=1…) now everything works perfectly! please tell me if this is the best way of doing this or if there is a faster or more “Professional” way of doing this. but now i have another issue.
when i close the game it says that the GET from inventory has an issue with the index value that i get from the output of my new function that sets the variable for LastButtonSelected. i know that it passes an int and everything should be fine. and i know that the variable is passing a valid index because the remove node runs off the same variable for index and it works fine.
one more thing is that with the GET node. it work fine as well. nothing wrong with the functionality while in game. but i still get an error when i close the game preview… i would love any help i could get because it drives me nuts lol
Thank you in advance!
The warning message you receive is likely cased by the function trying to access an index outside of whatever array you’re using to store for the variables. You may need to check the beginning and ending bounds that the function references.
Cheers