- Site Map >
- Modding and Creation >
- Sims 2 Creation >
- Modding Discussion >
- Attributes on an object in inventory appear to be read-only
- Site Map >
- Modding and Creation >
- Sims 2 Creation >
- Modding Discussion >
- Attributes on an object in inventory appear to be read-only
Replies: 2 (Who?), Viewed: 5100 times.
#1
5th Feb 2017 at 9:08 PM
Last edited by whoward69 : 5th Feb 2017 at 9:33 PM.
Attributes on an object in inventory appear to be read-only
I have an object that I'm using to store data about the owning sim - specifically the number of days worked. So every time the Sim gets paid, the days value in an attribute is incremented.There is also a Show Values action to display the data.
If the object is on the bedside table (ie NOT in the owning Sims inventory), I get the expected behaviour
* Show Values - days = 2 (say)
* Sim goes to work and comes home, gets paid. BHAV on the object gets called, reads some attributes, does some calculations, spits out the answer in a notification (this is all correct). As part of the BHAV, days is incremented
* Show Values - days = 3 (which is correct)
Now, if the object is in the Sim's inventory, I get a "read-only" behaviour
* Show Values - days = 3 (say)
* Sim goes to work and comes home, gets paid. BHAV on the object gets called, reads some attributes, does some calculations, spits out the answer in a notification (this is all correct). As part of the BHAV, days is incremented
* Show Values - days = 3 (which is incorrect, it should be 4)
Same "read-only" behaviour can be seen when the Sim quits their job (which resets days to 0) - if the object is not in the inventory, I get the correct value of 0. If the object is in the Sim's inventory it doesn't change, ie I get the old value.
Anybody happen to of come across something similar and know the solution?
TIA
W
Edit: Mmmmmm
There is another possibility ....
Get copy of object from inventory, show values from the copy, discard copy
Get copy of object from inventory, perform paid actions on copy, discard copy
Get copy of object from inventory, show values, discard copy
Which is probably what's happening ...
Now, how to deal with that sequence of events ...
Advertisement
#2
6th Feb 2017 at 8:56 AM
And the nominations for the category "Worst named parameter" go to ...
"Don't Delete" for meaning "Make A Copy"
When you place an item into the inventory, you don't. You put a copy into the inventory. The "Don't Delete" parameter determines if the original object is destroyed or not.
When you get an item from the inventory, you don't. You get a copy, and the "Don't Delete" parameter determines if the original in the inventory is destroyed.
So to work on an item in the inventory, you need to
a) Find it
b) Get it a copy of it, deleting the original from the inventory
c) Work on the copy
d) Put a copy of the copy back into the inventory, deleting the copy
"Don't Delete" for meaning "Make A Copy"
When you place an item into the inventory, you don't. You put a copy into the inventory. The "Don't Delete" parameter determines if the original object is destroyed or not.
When you get an item from the inventory, you don't. You get a copy, and the "Don't Delete" parameter determines if the original in the inventory is destroyed.
So to work on an item in the inventory, you need to
a) Find it
b) Get it a copy of it, deleting the original from the inventory
c) Work on the copy
d) Put a copy of the copy back into the inventory, deleting the copy
Code:
class SimInventory { private List<Item> items = new List<Item>(); public void addItem(Item item, bool dontDelete) { items.add(item.clone()); if (!dontDelete) { item.destroy(); } } public Item getItem(int index, bool dontDelete) { Item temp = items.get(index); Item item = temp.clone(); if (!dontDelete) { items.remove(index); temp.destroy(); } return item; } }
Scholar
#3
6th Feb 2017 at 2:01 PM
Posts: 1,055
Yes, that's almost correct. I have never seen anything attempt to make a change to an item in the inventory, it is actually just a token of the item while it is in the inventory so you must create the item from the inventory token to make changes.
a) find it's index (you'd have to do that any way)
b) Create the item, delete the token from the inventory
c) Work on the item
d) Re-create the inventory token of the updated item and delete the item.
I assume you are referring to the global op-codes 'Inventory - Visible - Get Item' (0x0000044B) and 'Inventory - Visible - Add Item' (0x0000044A). The param names are a part of SimPE (GLOBALS.package in this case) not from the game so you can change them if you like. Those two global op-codes are easy to work with once you are used to them.
a) find it's index (you'd have to do that any way)
b) Create the item, delete the token from the inventory
c) Work on the item
d) Re-create the inventory token of the updated item and delete the item.
I assume you are referring to the global op-codes 'Inventory - Visible - Get Item' (0x0000044B) and 'Inventory - Visible - Add Item' (0x0000044A). The param names are a part of SimPE (GLOBALS.package in this case) not from the game so you can change them if you like. Those two global op-codes are easy to work with once you are used to them.
Who Posted
|