ELEMENTALCRAFTER009 Posted February 6, 2015 Share Posted February 6, 2015 Alright, I'm new here so if there is anything missing please tell me but, I'm currently working on a custom character that will transform when sanity is at, or below, 11. The problem is that whenever I enable the mod the game doesn't necessarily crash, but instead freezes. Any advice will be useful.local MakePlayerCharacter = require "prefabs/player_common"local assets = { Asset( "ANIM", "anim/player_basic.zip" ), Asset( "ANIM", "anim/player_idles_shiver.zip" ), Asset( "ANIM", "anim/player_actions.zip" ), Asset( "ANIM", "anim/player_actions_axe.zip" ), Asset( "ANIM", "anim/player_actions_pickaxe.zip" ), Asset( "ANIM", "anim/player_actions_shovel.zip" ), Asset( "ANIM", "anim/player_actions_blowdart.zip" ), Asset( "ANIM", "anim/player_actions_eat.zip" ), Asset( "ANIM", "anim/player_actions_item.zip" ), Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ), Asset( "ANIM", "anim/player_actions_bugnet.zip" ), Asset( "ANIM", "anim/player_actions_fishing.zip" ), Asset( "ANIM", "anim/player_actions_boomerang.zip" ), Asset( "ANIM", "anim/player_bush_hat.zip" ), Asset( "ANIM", "anim/player_attacks.zip" ), Asset( "ANIM", "anim/player_idles.zip" ), Asset( "ANIM", "anim/player_rebirth.zip" ), Asset( "ANIM", "anim/player_jump.zip" ), Asset( "ANIM", "anim/player_amulet_resurrect.zip" ), Asset( "ANIM", "anim/player_teleport.zip" ), Asset( "ANIM", "anim/wilson_fx.zip" ), Asset( "ANIM", "anim/player_one_man_band.zip" ), Asset( "ANIM", "anim/shadow_hands.zip" ), Asset( "SOUND", "sound/sfx.fsb" ), Asset( "SOUND", "sound/wilson.fsb" ), Asset( "ANIM", "anim/beard.zip" ), Asset( "ANIM", "anim/trent.zip" ), Asset( "ANIM", "anim/ghost_trent_build.zip" ), Asset( "ANIM", "anim/trent_form.zip" ),}local prefabs = {}local start_inv = { "multitool_axe_pickaxe", "goldenshovel", "nightsword", }local function becometrent(inst) inst.AnimState:SetBuild("trent") inst.components.health:SetMaxHealth(150) inst.components.hunger:SetMax(200) inst.components.sanity:SetMax(80) inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 1) inst.components.sanity.dapperness = (TUNING.DAPPERNESS_HUGE * 1) inst.components.sanity.night_drain_mult = 0.5 inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.05) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.05)end local function becometrent_form(inst) inst.AnimState:SetBuild("trent_form") inst.Transform:SetScale(1.4, 1.4, 1.4) inst.components.health:SetMaxHealth(200) inst.components.hunger:SetMax(200) inst.components.sanity:SetMax(133) inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 1.25) inst.components.sanity.dapperness = (TUNING.DAPPERNESS_HUGE * 1.5) inst.components.sanity.night_drain_mult = 0.5 inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.3) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.3)end local function sanitychange(inst, data) if inst.components.sanity.current < 11 then becomebody(inst) else becomehed(inst) end end local fn = function(inst)-- This initializes for both clients and the hostlocal common_postinit = function(inst) -- Minimap icon inst.MiniMapEntity:SetIcon( "trent.tex" )end-- This initializes for the host onlylocal master_postinit = function(inst) -- choose which sounds this character will play inst.soundsname = "trent" -- Stats inst.components.health:SetMaxHealth(150) inst.components.hunger:SetMax(200) inst.components.sanity:SetMax(80) inst.components.sanity.dapperness = (TUNING.DAPPERNESS_HUGE * 1) inst.components.sanity.night_drain_mult = 0.5 inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.05) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.05) inst:ListenForEvent("sanitydelta", sanitychange)endreturn MakePlayerCharacter("trent", prefabs, assets, common_postinit, master_postinit, start_inv) Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/ Share on other sites More sharing options...
ELEMENTALCRAFTER009 Posted February 6, 2015 Author Share Posted February 6, 2015 UPDATE: fixed the freezing, but I still crash Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/#findComment-610300 Share on other sites More sharing options...
Jjmarco Posted February 6, 2015 Share Posted February 6, 2015 local function sanitychange(inst, data) if inst.components.sanity.current < 11 then becomebody(inst) else becomehed(inst) end end Where are the becomebody and becomehed functions defined? Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/#findComment-610388 Share on other sites More sharing options...
ELEMENTALCRAFTER009 Posted February 6, 2015 Author Share Posted February 6, 2015 Where are the becomebody and becomehed functions defined?That's what fixed the freezing, since I changed it to becometrent and becometrent_form, but now I get a different error relating to common_postinitlocal MakePlayerCharacter = require "prefabs/player_common"local assets = { Asset( "ANIM", "anim/player_basic.zip" ), Asset( "ANIM", "anim/player_idles_shiver.zip" ), Asset( "ANIM", "anim/player_actions.zip" ), Asset( "ANIM", "anim/player_actions_axe.zip" ), Asset( "ANIM", "anim/player_actions_pickaxe.zip" ), Asset( "ANIM", "anim/player_actions_shovel.zip" ), Asset( "ANIM", "anim/player_actions_blowdart.zip" ), Asset( "ANIM", "anim/player_actions_eat.zip" ), Asset( "ANIM", "anim/player_actions_item.zip" ), Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ), Asset( "ANIM", "anim/player_actions_bugnet.zip" ), Asset( "ANIM", "anim/player_actions_fishing.zip" ), Asset( "ANIM", "anim/player_actions_boomerang.zip" ), Asset( "ANIM", "anim/player_bush_hat.zip" ), Asset( "ANIM", "anim/player_attacks.zip" ), Asset( "ANIM", "anim/player_idles.zip" ), Asset( "ANIM", "anim/player_rebirth.zip" ), Asset( "ANIM", "anim/player_jump.zip" ), Asset( "ANIM", "anim/player_amulet_resurrect.zip" ), Asset( "ANIM", "anim/player_teleport.zip" ), Asset( "ANIM", "anim/wilson_fx.zip" ), Asset( "ANIM", "anim/player_one_man_band.zip" ), Asset( "ANIM", "anim/shadow_hands.zip" ), Asset( "SOUND", "sound/sfx.fsb" ), Asset( "SOUND", "sound/wilson.fsb" ), Asset( "ANIM", "anim/beard.zip" ), Asset( "ANIM", "anim/trent.zip" ), Asset( "ANIM", "anim/ghost_trent_build.zip" ), Asset( "ANIM", "anim/trent_form.zip" ),}local prefabs = {}local start_inv = { "multitool_axe_pickaxe", "goldenshovel", "nightsword", }local function becometrent(inst) inst.AnimState:SetBuild("trent") inst.components.health:SetMaxHealth(150) inst.components.hunger:SetMax(200) inst.components.sanity:SetMax(80) inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 1) inst.components.sanity.dapperness = TUNING.DAPPERNESS_HUGE inst.components.sanity.night_drain_mult = 0.5 inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.05) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.05)end local function becometrent_form(inst) inst.AnimState:SetBuild("trent_form") inst.Transform:SetScale(1.5, 1.5, 1.5) inst.components.health:SetMaxHealth(200) inst.components.hunger:SetMax(200) inst.components.sanity:SetMax(133) inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 1.25) inst.components.sanity.dapperness = (TUNING.DAPPERNESS_HUGE * 1.5) inst.components.sanity.night_drain_mult = 0.5 inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.3) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.3)end local function sanitychange(inst, data) if inst.components.sanity.current < 10 then becometrent_form(inst) else becometrent(inst) end end local fn = function(inst)-- This initializes for both clients and the hostlocal common_postinit = function(inst) -- Minimap icon inst.MiniMapEntity:SetIcon( "trent.tex" ) end end-- This initializes for the host onlylocal master_postinit = function(inst) -- choose which sounds this character will play inst.soundsname = "trent" -- Stats inst.components.health:SetMaxHealth(150) inst.components.hunger:SetMax(200) inst.components.sanity:SetMax(80) inst.components.sanity.dapperness = TUNING.DAPPERNESS_HUGE inst.components.sanity.night_drain_mult = 0.5 inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.05) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.05) inst:ListenForEvent("sanitydelta", sanitychange)endreturn MakePlayerCharacter("trent", nil, prefabs, assets, fn, common_postinit, master_postinit, start_inv) Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/#findComment-610464 Share on other sites More sharing options...
ELEMENTALCRAFTER009 Posted February 6, 2015 Author Share Posted February 6, 2015 and now I get the error 1045: bad argument #1 to 'ipairs' (table expected, got function) Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/#findComment-610470 Share on other sites More sharing options...
ELEMENTALCRAFTER009 Posted February 6, 2015 Author Share Posted February 6, 2015 The thing is, I don't know where this error is talking about. Which function is supposed to be a table? Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/#findComment-610488 Share on other sites More sharing options...
rezecib Posted February 6, 2015 Share Posted February 6, 2015 (edited) 1045: bad argument #1 to 'ipairs' (table expected, got function) There should be a filename just before this part of the error. This will tell you what file to look in, and that it's line 1045 in that file. Edit: But your problem is here: MakePlayerCharacter("trent", nil, prefabs, assets, fn, common_postinit, master_postinit, start_inv) Go look at the arguments to the MakePlayerCharacter function in scripts/prefabs/player_common. You have too many there. Edited February 6, 2015 by rezecib Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/#findComment-610514 Share on other sites More sharing options...
ELEMENTALCRAFTER009 Posted February 6, 2015 Author Share Posted February 6, 2015 There should be a filename just before this part of the error. This will tell you what file to look in, and that it's line 1045 in that file. Edit: But your problem is here: Go look at the arguments to the MakePlayerCharacter function in scripts/prefabs/player_common. You have too many there.Yes. I know but, in there all it says is if starting_inventory ~= nil then for i, v in ipairs(starting_inventory) do table.insert(prefabs, v) end end and I'm not sure what to do with this. Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/#findComment-610538 Share on other sites More sharing options...
rezecib Posted February 7, 2015 Share Posted February 7, 2015 (edited) @ELEMENTALCRAFTER009, Yes, so that's where it's crashing. But scroll up and you'll see this, which is what I told you to look at.local function MakePlayerCharacter(name, customprefabs, customassets, common_postinit, master_postinit, starting_inventory) Edited February 7, 2015 by rezecib Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/#findComment-610550 Share on other sites More sharing options...
ELEMENTALCRAFTER009 Posted February 7, 2015 Author Share Posted February 7, 2015 @ELEMENTALCRAFTER009, Yes, so that's where it's crashing. But scroll up and you'll see this, which is what I told you to look at.local function MakePlayerCharacter(name, customprefabs, customassets, common_postinit, master_postinit, starting_inventory)Alright, now it doesn't crash immediately. However, it does crash whenever I join a world and shows this error screen. Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/#findComment-610565 Share on other sites More sharing options...
rezecib Posted February 7, 2015 Share Posted February 7, 2015 @ELEMENTALCRAFTER009, Try using Wolfgang's method of setting max health instead. Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/#findComment-610570 Share on other sites More sharing options...
ELEMENTALCRAFTER009 Posted February 7, 2015 Author Share Posted February 7, 2015 @ELEMENTALCRAFTER009, Try using Wolfgang's method of setting max health instead.I used Wolfgang's method for setting stats and it doesn't change the stats at all local health_max = 150 local hunger_max = 200 local sanity_max = 80 I also tried (TUNING.WILSON_insertstat) Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/#findComment-610597 Share on other sites More sharing options...
rezecib Posted February 7, 2015 Share Posted February 7, 2015 (edited) @ELEMENTALCRAFTER009, Hmm, well, it's not obvious to me why it's running into a stack overflow like that, but you can certainly reduce the number of times your function is running by a huge margin, if you change your code to this:local function sanitychange(inst, data) if inst.components.sanity.current < 10 and not inst.trentform then becometrent_form(inst) elseif inst.trentform then becometrent(inst) end endThen, at the beginning of becometrent set inst.trentform = false, and at the beginning of becometrent_form, set inst.trentform = true. This means that it'll only run the transformation functions when the sanitychange means that he should be switching. That being said, it's probably a good idea to have "stickiness" to the transition, by setting the threshold for trent->trentform a little lower than the threshold for trentform -> trent. This way you don't run into any flickering at the transition point. But I'm not very confident this will solve the immediate issue... Edit: You probably also want to be setting the scale in both transformation functions, otherwise your character will become irreversibly stuck at 1.5 scale. Edited February 7, 2015 by rezecib Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/#findComment-610621 Share on other sites More sharing options...
ELEMENTALCRAFTER009 Posted February 7, 2015 Author Share Posted February 7, 2015 (edited) @ELEMENTALCRAFTER009, Hmm, well, it's not obvious to me why it's running into a stack overflow like that, but you can certainly reduce the number of times your function is running by a huge margin, if you change your code to this:local function sanitychange(inst, data) if inst.components.sanity.current < 10 and not inst.trentform then becometrent_form(inst) elseif inst.trentform then becometrent(inst) end endThen, at the beginning of becometrent set inst.trentform = false, and at the beginning of becometrent_form, set inst.trentform = true. This means that it'll only run the transformation functions when the sanitychange means that he should be switching. That being said, it's probably a good idea to have "stickiness" to the transition, by setting the threshold for trent->trentform a little lower than the threshold for trentform -> trent. This way you don't run into any flickering at the transition point. But I'm not very confident this will solve the immediate issue... Edit: You probably also want to be setting the scale in both transformation functions, otherwise your character will become irreversibly stuck at 1.5 scale.So I would changelocal function becometrent_form(inst) inst.AnimState:SetBuild("trent_form") inst.Transform:SetScale(1.5, 1.5, 1.5)tolocal function becometrent_form(inst) inst.trentform = true inst.AnimState:SetBuild("trent_form") inst.Transform:SetScale(1.5, 1.5, 1.5)for both becometrent and becometrent_form. EDIT: and is inst.trentform supposed to be inst.trent_form or not? Also, stats are still not functioning properly so should I add this somewhere? inst.components.health:SetMaxHealth(health_max)inst.components.hunger:SetMaxHunger(hunger_max)inst.components.sanity:SetMaxSanity(sanity_max) Edited February 7, 2015 by ELEMENTALCRAFTER009 Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/#findComment-610625 Share on other sites More sharing options...
rezecib Posted February 7, 2015 Share Posted February 7, 2015 EDIT: and is inst.trentform supposed to be inst.trent_form or not? It shouldn't matter, you just have to give it a name and make sure you use the same name for that boolean value everywhere. As for the stats, I think you have them everywhere you need them. Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/#findComment-610631 Share on other sites More sharing options...
ELEMENTALCRAFTER009 Posted February 7, 2015 Author Share Posted February 7, 2015 (edited) It shouldn't matter, you just have to give it a name and make sure you use the same name for that boolean value everywhere. As for the stats, I think you have them everywhere you need them. Is there anything that could fix the stats then? EDIT: New bug when sanity is below the set value, it flickers back and forth between trent and trent_form regardless if it is at or below. Edited February 7, 2015 by ELEMENTALCRAFTER009 Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/#findComment-610633 Share on other sites More sharing options...
Developer bizziboi Posted February 7, 2015 Developer Share Posted February 7, 2015 Hmm, well, it's not obvious to me why it's running into a stack overflow like that, Hmmm, seems to me that sanity change message causes sanitychange to be called, which causes one of the setform's to be called which sets maxsanity, which calls sanity:DoDelta which fires a sanity change message, which calls sanitychange, which.....and down the rabbithole we go. You should only call setform if the oldpercentage is one one side of the treshold and the new on the other, or indeed as you suggested, check the form beforehand. I know your suggestion works, but just wanted to point out the stack overflow seems logical to me. Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/#findComment-610638 Share on other sites More sharing options...
ELEMENTALCRAFTER009 Posted February 7, 2015 Author Share Posted February 7, 2015 (edited) That being said, it's probably a good idea to have "stickiness" to the transition, by setting the threshold for trent->trentform a little lower than the threshold for trentform -> trent. This way you don't run into any flickering at the transition point.Now how would I go about doing this? since , again, I'm new to DST and especially modding. And thank you for all the help you've given me Edited February 7, 2015 by ELEMENTALCRAFTER009 Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/#findComment-610640 Share on other sites More sharing options...
Developer bizziboi Posted February 7, 2015 Developer Share Posted February 7, 2015 By having a treshold for going into the form, and another one for going out of it. The range inbetween the character will stay whatever he was when entering that range. So if sanity fluctuates around one of the treshold the character doesn't transform back and forth.local becomeformtreshold = 10local unbecomeformtreshold = 20if inst.components.sanity.current < becomeformtreshold and not inst.trentform then becometrent_form(inst)elseif inst.components.sanity.current > unbecomeformtreshold and inst.trentform then becometrent(inst)end Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/#findComment-610643 Share on other sites More sharing options...
ELEMENTALCRAFTER009 Posted February 7, 2015 Author Share Posted February 7, 2015 (edited) By having a treshold for going into the form, and another one for going out of it. The range inbetween the character will stay whatever he was when entering that range. So if sanity fluctuates around one of the treshold the character doesn't transform back and forth.local becomeformtreshold = 10local unbecomeformtreshold = 20if inst.components.sanity.current < becomeformtreshold and not inst.trentform then becometrent_form(inst)elseif inst.components.sanity.current > unbecomeformtreshold and inst.trentform then becometrent(inst)endVariable 'inst' is not declared. EDIT: Nvm fixed it XD Edited February 7, 2015 by ELEMENTALCRAFTER009 Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/#findComment-610648 Share on other sites More sharing options...
Developer bizziboi Posted February 7, 2015 Developer Share Posted February 7, 2015 @ELEMENTALCRAFTER009, That code is meant to replace the code inside sanitychange. Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/#findComment-610651 Share on other sites More sharing options...
ELEMENTALCRAFTER009 Posted February 7, 2015 Author Share Posted February 7, 2015 The final thing that still needs to be fixed is the stats. That's all. Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/#findComment-610653 Share on other sites More sharing options...
rezecib Posted February 7, 2015 Share Posted February 7, 2015 Variable 'inst' is not declared. Then you made a mistake somewhere, and aren't passing inst to the function or something. But "inst is not declared" is not something that can arise from that code, because it would run into "attempt to index inst" first. Also, try not to type your replies inside of the quote... it's a bit confusing. Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/#findComment-610654 Share on other sites More sharing options...
ELEMENTALCRAFTER009 Posted February 7, 2015 Author Share Posted February 7, 2015 @ELEMENTALCRAFTER009, That code is meant to replace the code inside sanitychange. Yeah, I figured that out quickly after I tested it XD. I'm tired Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/#findComment-610656 Share on other sites More sharing options...
ELEMENTALCRAFTER009 Posted February 7, 2015 Author Share Posted February 7, 2015 (edited) New bug again. trent will transform into trent_from and then will turn back to trent at the unbecomeformtreshold, but won't transform back into trent_form at the becomeformtreshold again. Edited February 7, 2015 by ELEMENTALCRAFTER009 Link to comment https://forums.kleientertainment.com/forums/topic/50594-help-character-transform-crash/#findComment-610665 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