Hello everyone!
I'm on a quest to learn about arrays and so far I've searched and read just about every post in the entire forum trying to understand how to use these things (arrays).
I've read about slots in the tutorial section (by Caba`drin ) https://forums.taleworlds.com/index.php/topic,142422.0.html
WARP (by Autolykos) https://forums.taleworlds.com/index.php/topic,335511.0.html
and about dynamic arrays (by Sphere). https://forums.taleworlds.com/index.php/topic,127910.msg3083905.html#msg3083905
I've also asked for help in the Q&A where I did receive a reply...
I decided to make an actual thread because there seems to be a gap in info between people who are fluent in working with arrays and those of us who aren't. I can't seem to make sense of how to correlate the data in an array to what I want the data to connect to. I don't doubt that I'm over-complicating, misunderstanding or just being completely dense about this but I thought that if I made a thread then hopefully other people would benefit from this as well.
So, moving on... as a learning project, I want to store a non-hero troops' inventory into an array (like a virtual inventory), clear the troops' actual inventory (I know how to do), save-n-reload game, then copy items from troops' virtual inventory to troops' actual inventory.
How I think it should happen:
I'll have to save the troops' actual inventory into a virtual inventory (as an array?)
I'll need to clear a troops' inventory
The troops' inventory that was cleared will need to have a "trigger" variable (a custom slot?) to indicate that the troops' inventory should be cleared at game_start
Retrieve the items from the array and give the items back to the troop
Reset the trigger that indicates the troops inventory should be cleared at game_start
As stated in my question in the Q&A section, I want to use Sphere's dynamic arrays because I can understand what is going on in each of the scripts and I understand how I can use them to modify the arrays.
What I don't understand is how I'm going to get items info into the arrays. I've looked everywhere for examples that I hoped would "show me the way" but I can't find any.
As replied to my question in the Q&A section, I would have to store at least 3 parts of each items' info (ID, IMOD and quantity) and then have them work together, which makes sense, but how?
I'm assuming that the three temp arrays correspond to the the info that each item needs to be represented?
Also as replied to my question, I can use fake troops as a chest of sorts, which again makes sense, and I'm assuming that I'll have to "mark" every item that goes into the fake troop/chest as belonging to a certain troop (if I decide to change more than 1 troops' inventory)
If/when I learn how to input an items data into an array I will know how I can retrieve that info. This is the only part that's got me caught up. Examples are greatly encouraged. Thanks in advance. Also, if there are notions I'm missing, please let me know.
I'm on a quest to learn about arrays and so far I've searched and read just about every post in the entire forum trying to understand how to use these things (arrays).
I've read about slots in the tutorial section (by Caba`drin ) https://forums.taleworlds.com/index.php/topic,142422.0.html
WARP (by Autolykos) https://forums.taleworlds.com/index.php/topic,335511.0.html
and about dynamic arrays (by Sphere). https://forums.taleworlds.com/index.php/topic,127910.msg3083905.html#msg3083905
I've also asked for help in the Q&A where I did receive a reply...
kalarhan said:Iron Sight said:I'm trying to learn arrays and while I know what I need to do with them, I can't completely figure them out. I want to create an array that stores items for troops like a virtual inventory and have that inventory apply itself every time the game is loaded. I've read the dynamic arrays post and this is most definitely what I want to use but I can't figure out or find an example of how I would create an item array for troops. Any help would be greatly appreciated. Also, I'm open to examples of how to use other types of arrays, like slots and whatever else there may be. Thanks.
first review this tutorial, in special the SLOT section https://forums.taleworlds.com/index.php/topic,142422.0.html
the system is 0-based. Entities can have a array of data (the slots), like a TROOP. What you can do is use a fake troop (not a actual character or soldier in the game) as a storage, and its slots to save the values you need.
example from VC:
Code:### These are used as arrays in the scripts. ["temp_array_a","{!}temp_array_a","{!}temp_array_a",tf_hero|tf_inactive, 0,reserved, fac_neutral,[],def_attrib|level(18),wp(60),knows_inventory_management_10, 0], ["temp_array_b","{!}temp_array_b","{!}temp_array_b",tf_hero|tf_inactive, 0,reserved, fac_neutral,[],def_attrib|level(18),wp(60),knows_inventory_management_10, 0], ["temp_array_c","{!}temp_array_c","{!}temp_array_c",tf_hero|tf_inactive, 0,reserved, fac_neutral,[],def_attrib|level(18),wp(60),knows_inventory_management_10, 0],
keep in mind that inventory/items are not a singular value. You have item_ID, quantity (when it is a ammo) and IMOD to save, so you will need to work with those 3 values for each item.
I decided to make an actual thread because there seems to be a gap in info between people who are fluent in working with arrays and those of us who aren't. I can't seem to make sense of how to correlate the data in an array to what I want the data to connect to. I don't doubt that I'm over-complicating, misunderstanding or just being completely dense about this but I thought that if I made a thread then hopefully other people would benefit from this as well.
So, moving on... as a learning project, I want to store a non-hero troops' inventory into an array (like a virtual inventory), clear the troops' actual inventory (I know how to do), save-n-reload game, then copy items from troops' virtual inventory to troops' actual inventory.
How I think it should happen:
I'll have to save the troops' actual inventory into a virtual inventory (as an array?)
I'll need to clear a troops' inventory
The troops' inventory that was cleared will need to have a "trigger" variable (a custom slot?) to indicate that the troops' inventory should be cleared at game_start
Retrieve the items from the array and give the items back to the troop
Reset the trigger that indicates the troops inventory should be cleared at game_start
As stated in my question in the Q&A section, I want to use Sphere's dynamic arrays because I can understand what is going on in each of the scripts and I understand how I can use them to modify the arrays.
What I don't understand is how I'm going to get items info into the arrays. I've looked everywhere for examples that I hoped would "show me the way" but I can't find any.
As replied to my question in the Q&A section, I would have to store at least 3 parts of each items' info (ID, IMOD and quantity) and then have them work together, which makes sense, but how?
I'm assuming that the three temp arrays correspond to the the info that each item needs to be represented?
Also as replied to my question, I can use fake troops as a chest of sorts, which again makes sense, and I'm assuming that I'll have to "mark" every item that goes into the fake troop/chest as belonging to a certain troop (if I decide to change more than 1 troops' inventory)
If/when I learn how to input an items data into an array I will know how I can retrieve that info. This is the only part that's got me caught up. Examples are greatly encouraged. Thanks in advance. Also, if there are notions I'm missing, please let me know.