AndRay Posted November 10, 2020 Share Posted November 10, 2020 I'm trying to mess with a new container in a crockpot-like prefab, and one of the important steps is generating the recipe outcome, which I have to do from the inside of the code (I need the flexibility of outputting multiple products at once) I tried using the lootdropper component but it didn't seem to drop the product in the right place. I have tried to use the GiveItem method but it crashed last time (I don't know if it's related to not having a src_pos argument or if I just set it wrong, but it executed and then crashed on the container definition file, so I know I sent something wrong) I then tried to replicate the relevant code, and trimmed it until it ran. It works fine in the master, but the container doesn't sync anymore in the client because I had to delete all PushEvent calls (they also crashed from nil indexing, just as the above remark, possibly because I failed to initialize the prefab I'm spawing correctly) Finally, coming back to debug it, I discover that it doesn't sync and now I'm in need of a different approach. So, how do I create items inside containers and then keep them synced? Do I need to initialize the item correctly? Do I need a different function? Or I should just use GiveItem and maybe I did something else wrong? Link to comment Share on other sites More sharing options...
penguin0616 Posted November 10, 2020 Share Posted November 10, 2020 Items inside of containers are normally replicated through a classified for the player who has the container open. Otherwise, they aren't replicated at all. You'll have to take a look at that classified. 1 Link to comment Share on other sites More sharing options...
AndRay Posted November 10, 2020 Author Share Posted November 10, 2020 Okay, I took a look at the code, traced the calls and it seems that the problem is the lack of a player to give a PushEvent command to. How can I refer to a player in the prefab context? Should I just pass the player when the action starts? Link to comment Share on other sites More sharing options...
penguin0616 Posted November 10, 2020 Share Posted November 10, 2020 I don't understand the question. The container classified already works with the player action to sync items. 1 Link to comment Share on other sites More sharing options...
AndRay Posted November 10, 2020 Author Share Posted November 10, 2020 (edited) The missing call and the crash problem is that the sync happens via a pair of Push/ListenForEvent with the event "itemget". Event methods are bound to a player entity (the container code does self.inst.components.inventoryitem.owner just to call this) If I want code to generate an item by myself, there is no player to access and therefore there is no valid entity on which to call PushEvent. How do I fix this? Edited November 10, 2020 by AndRay Link to comment Share on other sites More sharing options...
penguin0616 Posted November 10, 2020 Share Posted November 10, 2020 Are you trying to replicate the contents within a container, or just add an item to one? 1 Link to comment Share on other sites More sharing options...
AndRay Posted November 10, 2020 Author Share Posted November 10, 2020 I'm trying to add a new item inside a container, like a potato or a meatball. Link to comment Share on other sites More sharing options...
AndRay Posted November 10, 2020 Author Share Posted November 10, 2020 (edited) EDIT: I read the wrong line and call; and the right call is self.inst:PushEvent("itemget", { slot = in_slot, item = item, src_pos = src_pos }) as called by the container method (so self is the container itself) I call this not from the container component, because god no I don't ever want to hard code a copy of a container this way, but from the "stewer" component. So inst down here means the object itself. inst:PushEvent crashes because the method is nil. But inst.components.container:PushEvent and inst.components.container.inst:PushEvent crash in the game's container files (container_replica and container_classified which are not in the same folder) with the following error message: calling 'set' on bad self (table expected, got string) Also, for completeness, inst.components.container:GiveItem crashes on container.lua due to the code attempting to index my passed item for its components (which do not exist) Edited November 10, 2020 by AndRay Link to comment Share on other sites More sharing options...
penguin0616 Posted November 10, 2020 Share Posted November 10, 2020 (edited) inst.PushEvent shouldn't be nil, nor should GiveItem crash like that. Plus, you should use GiveItem over PushEvent. Can you share the full logs instead of a single snippet? Edited November 10, 2020 by penguin0616 1 Link to comment Share on other sites More sharing options...
AndRay Posted November 10, 2020 Author Share Posted November 10, 2020 (edited) I can! I was just sharing snippets because I kept bouncing between many different versions. I'll edit with the zipped mod and log file. EDIT: sorry for the delay. server_log.txt Masterchef.zip Edited November 10, 2020 by AndRay Link to comment Share on other sites More sharing options...
penguin0616 Posted November 11, 2020 Share Posted November 11, 2020 (edited) Looks like you're passing in a prefab string to :GiveItem, not an actual item. Edited November 11, 2020 by penguin0616 1 Link to comment Share on other sites More sharing options...
AndRay Posted November 11, 2020 Author Share Posted November 11, 2020 Aah, got it; scrambled v and loot in the code! Thanks a lot! Link to comment Share on other sites More sharing options...
penguin0616 Posted November 11, 2020 Share Posted November 11, 2020 You're welcome. 2 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now