Polariche Posted October 23, 2014 Share Posted October 23, 2014 I've made a custom component and a prefab that uses it, but the game keeps crashing on 'inst:AddComponent("mycomponent")I've tried deleting everything except the 'Class' part in the component code, and the mod still crashed. This is what the codes look like:Note: Of course, I'm not using 'mycomponent' and 'myprefab' in the actual mod. I just edited them : ) scripts/components/mycomponent.lua:local Mycomponent = Class(function(self, inst) self.inst = inst self.meat = nil self.spoiltime = nil self.spoiledproduct = "spoiledfood" self.inst:AddTag("mycomponent")end)scripts/prefabs/myprefab.lua:local assets = { Asset("ANIM", "anim/skeletons.zip"),}local prefabs ={ "monstermeat" }local animstates = {1, 3, 4, 5, 6} --not going to use the spear skeleton until anim to take spear is madelocal function onsave(inst, data) data.anim = inst.animnumendlocal function onload(inst, data) if data then if data.anim then inst.animnum = data.anim inst.AnimState:PlayAnimation("idle"..inst.animnum) end endendlocal function onharvest(inst) inst.AnimState:PlayAnimation("idle2")endlocal function onspoil(inst) inst.AnimState:PlayAnimation("idle2")endlocal function fn() local inst = CreateEntity() local trans = inst.entity:AddTransform() local anim = inst.entity:AddAnimState() MakeObstaclePhysics(inst, 0.25) inst.animnum = animstates[math.random(#animstates)] anim:SetBank("skeleton") anim:SetBuild("skeletons") anim:PlayAnimation("idle"..inst.animnum) inst:AddComponent("inspectable") inst.components.inspectable:RecordViews() inst.OnLoad = onload inst.OnSave = onsave local meat = "monstermeat" inst:AddComponent("mycomponent") --inst.components.longpork:SetOnHarvest(onharvest) --inst.components.longpork:SetOnSpoil(onspoil) --inst.components.longpork:SetMeat(meat) return instendreturn Prefab("common/objects/myprefab", fn, assets, prefabs) (Yeah, this is just skeleton.lua with a few lines added) Am I missing something? Am I required to specify the new components somewhere like prefabs? Or is it impossible to add a new component? Link to comment Share on other sites More sharing options...
Mobbstar Posted October 23, 2014 Share Posted October 23, 2014 Of course you can add a custom component. Just make sure you always write it the exactly same way (you capitalized it in the first line). You make a variable "inst" for "self.inst" but try to do "self.inst" afterwards... change that. Also, do you get an crash-log? (log.txt) That should tell a bit more. Link to comment Share on other sites More sharing options...
_Q_ Posted October 23, 2014 Share Posted October 23, 2014 at the end of the component class behind the end) return Mycomponent Link to comment Share on other sites More sharing options...
Polariche Posted October 23, 2014 Author Share Posted October 23, 2014 Of course you can add a custom component. Just make sure you always write it the exactly same way (you capitalized it in the first line). You make a variable "inst" for "self.inst" but try to do "self.inst" afterwards... change that. Also, do you get an crash-log? (log.txt) That should tell a bit more. It turns out I've forgotten to add 'return Mycomponent' at the end of the script. silly me!plot twist: The game still crashes even after adding that removing 'self.inst = inst' didn't work, either. I suppose I'll try my luck tomorrow... Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.