TheCricket Posted January 4, 2015 Share Posted January 4, 2015 I am new to scripting but not to programming, but I have been wrestling with a few concepts in Papyrus. I tried doing a lot of searching but to no avail so I decided to be more direct. Was hoping someone could help me with something. I created a function and am trying to pass an object into it as an argument. Then inside I want it to add an Item to it. The first Objects I pass in will be containers. The second argument will be the item to add. see example. Function AddItemToContainer(ObjectReference container, ObjectReference item) container.AddItem(item, 1)EndFunction Now the actual code is a bit more complex but this is the part that matters. I get this and the rest should work. What I am passing in. ObjectReference Property SKHFMilkCrateC AutoPotion Property BYOHFoodMilk AutoSo the Properties are set up, i am sure because other script is accessing them just fine.The function call AddItemToContainer(SKHFMilkCrateC, BYOHFoodMilk) As for the errors Container is not a variable andcannot cast a container to a objectreference, types are incompatible I just don't, despite my searching, understand the data structures. It doesnt seem to recognize the arguments as objects, it seems to claim i am giving them the classes not the instances. Can I change the arguments to Form, but if i do they don't seem to have access to the AddItem function as it is not a member function of form. I have tried to figure out typecasting using "as" but I have the same problem, it just said I am giving it the class not an instance. Anybody who has a deeper understanding of these things and would be willing to advise me I would be grateful. The code i am using is all quite a bit more complex, but this is a boiled down version. The rest is just passing Ints, so boring. Just a little mod tweak for myself. Link to comment Share on other sites More sharing options...
Arocide Posted January 4, 2015 Share Posted January 4, 2015 (edited) It's seeing container as a type, papyrus is case-insensitive hence the error, the actual type script for Container doesn't have any Functions or Properties but it does derive from Form. The second is a consequence of the first I believe... since it would be none. Edited January 4, 2015 by Arocide Link to comment Share on other sites More sharing options...
lofgren Posted January 4, 2015 Share Posted January 4, 2015 1. You can't use container as a variable because it is already a keyword type. Replace with akContainer (or anything else that isn't a reserved term). 2. A potion is not an ObjectReference. Object references are, well, objects that exist in the game which reference a form. Potions are a type of form. Change ObjectReference item to Form item in the function's definition. Link to comment Share on other sites More sharing options...
TheCricket Posted January 4, 2015 Author Share Posted January 4, 2015 Awesome Guys, Thx! Spent so much time searching myself, and you lot got it right away. Very cool. Link to comment Share on other sites More sharing options...
Recommended Posts