Cruces Posted July 21, 2013 Share Posted July 21, 2013 Hello, I'm trying to create a mod that will craft two stones, I managed to add the recipe in the recipe tab, and created the prefabs for them however when i click on the recipe to create those items I get an error without adding the AddPhysics() line I got an unknown error after adding it i got the error "attempt to call method 'AddPhysics' (a nil value)" below is the code of my prefablocal assets ={ Asset("IMAGE", "images/inventoryimages/angelstone.tex"), Asset("ATLAS", "images/inventoryimages/angelstone.xml"), Asset("IMAGE", "images/inventoryimages/devilstone.tex"), Asset("ATLAS", "images/inventoryimages/devilstone.xml"),}local function use_stone(inst) print "started using" if inst:HasTag("angelstone") then print "used angelstone" elseif inst:HasTag("devilstone") then print "used devilstone" else print "WTF?" endendlocal function commonfn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddSoundEmitter() inst:AddPhysics() MakeInventoryPhysics(inst) inst:AddComponent("inventoryitem") --inst.AddComponent("useableitem") --inst.components.useableitem:SetOnUseFn(use_stone) --inst:AddComponent("inspectable") --inst.entity:AddTransform() --inst.entity:AddAnimState() return instendlocal function angelstone() local inst = commonfn() inst:AddTag("angelstone") inst.components.inventoryitem.atlasname = "images/inventoryimages/angelstone.xml"endlocal function devilstone() local inst = commonfn() inst:AddTag("devilstone") inst.components.inventoryitem.atlasname = "images/inventoryimages/devilstone.xml"endreturn Prefab( "common/inventory/angelstone", angelstone, assets), Prefab( "common/inventory/devilstone", devilstone, assets) what am I doing wrong? Link to comment https://forums.kleientertainment.com/forums/topic/24356-mod-help-crash-when-addphysics-executes/ Share on other sites More sharing options...
Cruces Posted July 21, 2013 Author Share Posted July 21, 2013 dammit, another useless thread by me.... they really should allow people to delete them, please ignore this ): Link to comment https://forums.kleientertainment.com/forums/topic/24356-mod-help-crash-when-addphysics-executes/#findComment-258070 Share on other sites More sharing options...
debugman18 Posted July 21, 2013 Share Posted July 21, 2013 dammit, another useless thread by me.... they really should allow people to delete them, please ignore this ):Not useless! Someone else might have had the same problem as you. Did you get it solved? Link to comment https://forums.kleientertainment.com/forums/topic/24356-mod-help-crash-when-addphysics-executes/#findComment-258081 Share on other sites More sharing options...
simplex Posted July 21, 2013 Share Posted July 21, 2013 Not useless! Someone else might have had the same problem as you. Did you get it solved?My guess is he did, by replacing inst:AddPhysics() with inst.entity:AddPhysics(). Link to comment https://forums.kleientertainment.com/forums/topic/24356-mod-help-crash-when-addphysics-executes/#findComment-258265 Share on other sites More sharing options...
debugman18 Posted July 21, 2013 Share Posted July 21, 2013 My guess is he did, by replacing inst:AddPhysics() with inst.entity:AddPhysics().I'll have to take note of that for future use.I hate to branch off from the topic, but I had a question for you [MENTION=44092]simplex[/MENTION]Could you tell me how I can have this actually occur during the game? If I remove the item check, it all works as it should. I think that the reason it isn't working is because I'm checking to see if "candle" is equipped, and that check doesn't run constantly?Or am I checking for the equipped item incorrectly?function go_away(inst) inst:DoTaskInTime(0, function() local MainCharacter = GetPlayer() local has_candle = MainCharacter.components.inventory:IsItemEquipped("candle") if has_candle then print "Run away, little monster!" no_harm = 100 inst.components.combat:BlankOutAttacks(no_harm) end end)endfunction scared_away(inst) inst:AddTag("scared") inst:AddComponent("playerprox") inst.components.playerprox:SetDist(6,10) inst.components.playerprox:SetOnPlayerNear(go_away)end--List of enemies that can be kept away.AddPrefabPostInit('spider', scared_away) Link to comment https://forums.kleientertainment.com/forums/topic/24356-mod-help-crash-when-addphysics-executes/#findComment-258290 Share on other sites More sharing options...
simplex Posted July 21, 2013 Share Posted July 21, 2013 I'll have to take note of that for future use.I hate to branch off from the topic, but I had a question for you [MENTION=44092]simplex[/MENTION]Could you tell me how I can have this actually occur during the game? If I remove the item check, it all works as it should. I think that the reason it isn't working is because I'm checking to see if "candle" is equipped, and that check doesn't run constantly?Or am I checking for the equipped item incorrectly?function go_away(inst) inst:DoTaskInTime(0, function() local MainCharacter = GetPlayer() local has_candle = MainCharacter.components.inventory:IsItemEquipped("candle") if has_candle then print "Run away, little monster!" no_harm = 100 inst.components.combat:BlankOutAttacks(no_harm) end end)endfunction scared_away(inst) inst:AddTag("scared") inst:AddComponent("playerprox") inst.components.playerprox:SetDist(6,10) inst.components.playerprox:SetOnPlayerNear(go_away)end--List of enemies that can be kept away.AddPrefabPostInit('spider', scared_away)Just by looking at the code, I'd say it's doing what it was written to do: prevent enemies from attacking you. You'd still have to write some sort of code to apply movement in the opposite direction of the player, since currently there is none. But, as general notes, you should really set no_harm to something much lower (such as 2, just don't set it below 0.333), and preferably declare it local. And you don't really have to put it inside a DoTaskInTime call, just do it directly. go_away gets called every 0.333 seconds whenever the player is close enough. Link to comment https://forums.kleientertainment.com/forums/topic/24356-mod-help-crash-when-addphysics-executes/#findComment-258311 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