Hello,
I currently have a column with labels for displaying the "stats" (i.e property values) of highlighted inventory items.
Ideally, I'd like to display what the player's stats would be if they equipped it; i.e the property value + the global variable that holds the player's stat in question. Normally it's easy to include an operator to add two variable integers, but how do I turn the highlighted inventory item's properties into a variable?
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
The currently-highlighted item instance can be read with the HoverInstance property:
From there, you can extract the intended property and set it to e.g. a Text variable with:
Sorry, but I don't understand why I would want to make the values strings instead of ints? My idea is that I set the label to display a value that is the sum of a global variable and the property value of the highlighted inventory item.
This is what I have so far (never mind the different nomenclature; the stats were renamed at one point).
If the code seems legit, I need to find a way to update this so that it repeatedly checks for highlighted items (right now the script has Start, but I need an update method here)
Ok, after fixing some typos I got this to work - my method right now is that I add a prefab object with the script every time I open the Menu and remover it when I close the menu again. Then the I use the Update() method to check for the highlighted item.
Update:
Rats, I now realize it wasn't this simple. Using this method, I can only show what the character's stats would be if the highlighted item was the only item equipped. I forgot that I need to take into account the already equipped items of other types.
I currently have one container for every part of the body that can be equipped. But now I need to check if each container has an item, and, if it's the same type (a fifth property with the string "body", "head" etc) as the highlighted item, ignore its bonuses (since it's the item that is potentially replaced) but items of other types should have their bonuses accounted for...
All stats have a corresponding "base" variable to keep track of the unaugmented stat.
I think I might need a hint or two to pull this off...
No problem, I'm just sharing generic example code - adapt as needed.
Renaming Start to Update should be enough. We can see about moving to events later, to avoid it running every frame, but for now it's important to just get the calculation correct.
Generally speaking, you'd have a reference to each of the Containers, iterate through them and tot up their stats onto the hoverInstance. Something like:
I think I'm following. But a few questions:
I assume I have to repeat the above for each of the 4 stats properties? So something like this:
If I'm on the right track, I'll again set the total values to the global variables.
Two more questions:
1. How do I define or reference the containers?
2. How do I call the Calculate ()?
Update:
I'm slowly progressing here, and this is what I have so far:
I feel like I'm on the right track, although I can't get the exact right numbers yet. Or actually, they aren't right at all - most of them are much too high, and I'm trying to find out what the problem is. It feels like part of the problem is that the base values are counted twice, but that alone isn't enough.
PS: As you can see I first tried making a list with the containers, but that proved complicated since the containers are already in use in another script (this one: https://adventurecreator.org/forum/discussion/11681/equipment-window/p2)
so I'm going with this findobjectsoftype method now.
The use of FindObjectsOfType may be the issue - this will search for all Containers in the scene.
If the numbers are wrong, I'd recommend simplifying and building things up from there.
Start with just one property, and store it in a temporary int as I was earlier. You can update the GlobalVariable with the final int value at the end of the function, and you can then place Debug.Log statements at each stage to help show what's going on.
Somethine like:
Ok, this is super confusing. Trying out your code, it works perfectly.
I add the second variable and property, but this one won't add up right. I'm struggling to see a pattern, but it's like it's completely messing up which values to add.
I'm commenting out the debugs for now, since I can easily monitor all the values by looking at the variables while I test the code
I'm gonna try to explain how the values are changed with the code from above, to see if you can work out the pattern.
Just for testing purposes, I've set all the base stats to 5. Just to be clear, I'm only testing the first two stats/variables/properties now.
Hovering over an item with the stats (Soft 0, Sophistication 0):
Correctly showing HoverSoft as 5
Incorrectly showing HoverSophistication as 7 (?)
Hovering over an item with identical stats, but this time a different "type" ("body" instead of "head")
Both variables = 5 (correctly
Hovering over an item with the stats (0, 2)
HoverSoft = 5
HoverSophistication = 9
With one garment equipped (2, 0) bringing the first base stat up to 7:
Hovering over an item with (0, 0):
Showing both as 7 (should be 7, 5)
Hovering over an item with (0, 2):
HoverSoft = 7
HoverSophistication = 9 (effectively doubling the hover value)
If I add Street/cunning, I get similar results. Sophistication and Street almost always get extra points, sometimes exactly doubling the hover-value, but sometimes not.
Re-add the logs for the Sophistication - we need to see exactly what's being added and from where.
Trying with base value 5, hovering over a +2 item:
Logs:
Hover sophistication: 2, Base: 5, Total before containers: 7 [correct]
Container AC.Container[] found with sophistication: 2, New total: 9 [incorrect, there are no containers with items in them, let alone with sophistication bonuses]
Final total: 9
Update:
Similar results with Street/Cunning, only now it's
"Container AC.Container[] found with Street: 4"
Update:
Ok, I solved this for now.
First I made a list of names of containers that the script should search for, and then it almost worked, and finally I spotted the error; there was an old naming confusion where I had accidentally mixed up two containers.
It now works as intended, although I fear the code is quite clunky
Edit:
Argh, I spoke too soon. To be updated.
Ok it looks now that the HeadContainer isn't included in the mix, for whatever reason. I've checked the spelling a gazillion times. The current code:
Edit #123123:
Ok, it's still not working, but now I realized why it was so messed up before; there was indeed another container in the room, that was discontinued literally years ago when I changed how the wardrobe works. I noticed this by checking which containers are being processed by the script.
This log also tells me that after the point where the script only processes the containers on that list, the HeadContainer is no longer included. Inexplicably.
Last update from me, and sorry about the clutter:
When I remove the name requirement, everything works as intended. There shouldn't be any containers storing garments with properties in the game, so for now I'm considering this solved!
Thanks for your patience