As part of a demo I have been working on for an RPG, I have made gameplay tags for particular items needed for one of five tasks in that demo. Though I’ve made a data table for each item, I am unsure as to how to set a quantity for each item. This is so the game will know how many of each listed item the player has, and it will also be used as a condition to determine if the task is done successfully.
Kind of. You need to get their inventory as an array and then for each, if “has Tag” then add it to another array. If array LEN > your specified number, then you have a True or false bool!
Hope that helps!
I did consider using arrays, actually. I wasn’t sure if it was the correct approach. But okay, I’ll try that. Though how do I add an array attribute to a preexisting gameplay tag?
There will be a dialogue widget that will show text based on whether or not the player has the correct items and needed numbers. If I used a map variable, I wouldn’t be able to cast to it, since one can’t cast to any variables within a level BP.
So would a struct be a group of variables suitable for any and all items and equipment to be found or purchased in an RPG, as well as the quantity of each? Can you also point me to any straightforward tutorials if you know of any, please?
Now I have one last question: what’s the best way to put in a quantity (number of items currently held by the player)? Should I use an integer or a float? Or something else?
Another thing you could use is a map! Look into those!
You could have the object as the first half (key) and the int as the second half (value) then any time you need you call the key and it returns the value!
I don’t know if you saw the screenshot I posted earlier of the structure I made, but I made a struct then a data table based on it. So now, I’m at one last impasse: how do I cast to a variable within the struct variable? Like, say, I want the game to detect whether or not the player not only has a certain item but also the correct number of items? (Which would be, in this case, the ItemName (Name) and Quantity (Integer) variables.)
The first half of the map would be a Name, the second half (value) would be a struct based on that name. Then the struct would hold all of the data related to that name. The map puts them into a searchable list (you would use “Find” to get the one you need with a name input).
Would you happen to know of any good tutorials on how to make structs work with BPs that cast to their individual variables within a struct? That is, one that works with UE5?
You NEED a map. This will not work unless you use one.
Unless each item has its own struct, you can’t search through a bunch of structs for the one you need, you have to specify. The map would allow you to specify which one you need by passing in a string, name, or text variable (or other kinds but for this stick to one of those three).
Otherwise, you can just use “Set Members” and then “Set Struct” to save values,
and “Get” then break the output pin on the struct to Get a value- but you have to have already specified the struct, as I stated.
Also, casting doesn’t do what I think you think it does… It’s not a “Get” node, it’s a reshaping node. You cannot cast to variables (though you can cast a struct to another struct). What that means is you can make struct A BEHAVE AS struct B. Another word for cast is mold, if that helps?