ArashiOtter Posted February 9, 2015 Share Posted February 9, 2015 Hello again all, I am currently in the process of reworking my character Arashi Otter and was wondering if there was a way to call a function into another function in a clean simple manner, I already have a custom sanity function, and want another function to when I reach certain sanity levels gain certain stat's or loose certain stats. Again any help is greatly appreciated thanks in advance, -Arashi Link to comment https://forums.kleientertainment.com/forums/topic/50774-tying-a-custom-function-into-another-custom-function/ Share on other sites More sharing options...
Kzisor Posted February 9, 2015 Share Posted February 9, 2015 @ArashiOtter, without your current code and the location in which the second function is located it's difficult to tell you how to hook it up properly. However, if the function is in the same file as the other function simply use FUNCTIONNAME(FUNCTION, ARGUMENTS, TO, PASS) and it will call it. If you are using a local function then the local function needs to be at the beginning of the file. If it's located in another file then you need to attach it to a component or instances and call it via component:FunctionName() or inst:FunctionName() to pass the self variable automatically or component.FunctionName() or inst.FunctionName() to not pass the self variable automatically. Link to comment https://forums.kleientertainment.com/forums/topic/50774-tying-a-custom-function-into-another-custom-function/#findComment-611393 Share on other sites More sharing options...
ArashiOtter Posted February 9, 2015 Author Share Posted February 9, 2015 local function sanityfn(inst) local delta = 0 if TheWorld.state.isday then delta = -0.18 elseif TheWorld.state.isdusk then delta = 0.5 elseif TheWorld.state.isnight then delta = 0.95 end return delta end local function sanityeffects(sanityfn, inst)would that be the proper way to tie in it? Link to comment https://forums.kleientertainment.com/forums/topic/50774-tying-a-custom-function-into-another-custom-function/#findComment-611396 Share on other sites More sharing options...
Kzisor Posted February 9, 2015 Share Posted February 9, 2015 (edited) local function sanityfn(inst) local delta = 0 if TheWorld.state.isday then delta = -0.18 elseif TheWorld.state.isdusk then delta = 0.5 elseif TheWorld.state.isnight then delta = 0.95 end return deltaendlocal function sanityeffects(sanityfn, inst)would that be the proper way to tie in it? This code doesn't really demonstrate what you are trying to accomplish. However there are some mistakes.local function sanityfn(inst) local delta = 0 if TheWorld.state.isday then delta = -0.18 elseif TheWorld.state.isdusk then delta = 0.5 elseif TheWorld.state.isnight then delta = 0.95 end return deltaendlocal function sanityeffects(inst, sanitydelta)First inst is the first function parameter always. Second don't name the second parameter the same name as a function, that's bad coding. Name it what it's meant to represent. In order to call this function you could use:sanityeffects(inst, sanityfn(inst))or alternatively you can do something like:sanityeffects(inst)local delta = sanityfn(inst)By using the second method the only function parameter for sanityeffects needed is inst. Edited February 9, 2015 by Kzisor Link to comment https://forums.kleientertainment.com/forums/topic/50774-tying-a-custom-function-into-another-custom-function/#findComment-611398 Share on other sites More sharing options...
ArashiOtter Posted February 9, 2015 Author Share Posted February 9, 2015 (edited) I'm trying to make it so that based on the output of sanityfn arashi gains looses state, so during the day as he is loosing sanity he looses health or has a lower base health. likewise during the dusk and night he gains increasing health or a slow regen, and increase locmotor speed. Is there an easier way to write these two function to make it simpler? Like I've said before I really am not that good at writing script Edited February 9, 2015 by ArashiOtter Link to comment https://forums.kleientertainment.com/forums/topic/50774-tying-a-custom-function-into-another-custom-function/#findComment-611402 Share on other sites More sharing options...
Kzisor Posted February 9, 2015 Share Posted February 9, 2015 (edited) @ArashiOtter, there is an easier way of accomplishing that.local function snaityeffects(inst, phase)if phase == "day" then -- CHANGE THE DAY EFFECTS HERE. elseif phase = "dusk" then -- CHANGE THE DUSK EFFECTS HERE elseif phase == "night then -- CHANGE THE NIGHT EFFECTS HERE endendinst:WatchWorldState("phase", sanityeffects) This code doesn't require you to have two function, it should do it all in the sanity effects function. Edited February 9, 2015 by Kzisor Link to comment https://forums.kleientertainment.com/forums/topic/50774-tying-a-custom-function-into-another-custom-function/#findComment-611403 Share on other sites More sharing options...
ArashiOtter Posted February 9, 2015 Author Share Posted February 9, 2015 Ok using this script how would I change the sanity rate, I've triedinst.components.sanity:DoDelta(#)and have triedinst.components.sanity:SetRate(#)SetRateCrashes the game on the second day and DoDelta does nothing. Link to comment https://forums.kleientertainment.com/forums/topic/50774-tying-a-custom-function-into-another-custom-function/#findComment-611414 Share on other sites More sharing options...
Kzisor Posted February 9, 2015 Share Posted February 9, 2015 @ArashiOtter, the reason the second code crashes the game is because the sanity component does not have a SetRate function. You set it by using the following code:inst.components.sanity.rate = NEW_RATE Whenever you are trying to modify a component, you should first look at the component in question and determine how it works. Then you should adjust your code to work with the component the way you want it to be modified. Link to comment https://forums.kleientertainment.com/forums/topic/50774-tying-a-custom-function-into-another-custom-function/#findComment-611415 Share on other sites More sharing options...
ArashiOtter Posted February 9, 2015 Author Share Posted February 9, 2015 Ok so I have modified the codes for sanity ratelocal function sanityeffects(inst, phase) if phase == "day" then inst.components.sanity.rate = -0.18 elseif phase == "dusk" then inst.components.sanity.rate = 0.5 elseif phase == "night" then inst.components.sanity.rate = 0.95 end end but still the game wants to use it's sanity rate. I have yourinst:WatchWorldState("phase", sanityeffects)in my master_postinit cause it crashes my game if I place it anywhere else. Link to comment https://forums.kleientertainment.com/forums/topic/50774-tying-a-custom-function-into-another-custom-function/#findComment-611417 Share on other sites More sharing options...
Kzisor Posted February 9, 2015 Share Posted February 9, 2015 @ArashiOtter, try replacing rate with dapperness. However, if you are going to do that you will need to adjust your equation to take the current dapperness of the character and reduce it by the amount you want so something like the following;inst.components.sanity.dapperness = inst.components.sanity.dapperness - AMOUNT_TO_REDUCE I believe that dapperness is actually the variable we want to set because rate is being recalculated several times now that I took a closer look. Link to comment https://forums.kleientertainment.com/forums/topic/50774-tying-a-custom-function-into-another-custom-function/#findComment-611419 Share on other sites More sharing options...
ArashiOtter Posted February 9, 2015 Author Share Posted February 9, 2015 Ok so dapperness works I have to tweak values some more but, I have to wait til day two for the effect to happen anything to make it happen on day one? Link to comment https://forums.kleientertainment.com/forums/topic/50774-tying-a-custom-function-into-another-custom-function/#findComment-611436 Share on other sites More sharing options...
Kzisor Posted February 9, 2015 Share Posted February 9, 2015 @ArashiOtter, call the sanityeffects function from your master_postinit function.sanityeffects(inst, TheWorld.state.phase) Link to comment https://forums.kleientertainment.com/forums/topic/50774-tying-a-custom-function-into-another-custom-function/#findComment-611438 Share on other sites More sharing options...
ArashiOtter Posted February 9, 2015 Author Share Posted February 9, 2015 ok it works thank you Link to comment https://forums.kleientertainment.com/forums/topic/50774-tying-a-custom-function-into-another-custom-function/#findComment-611442 Share on other sites More sharing options...
ArashiOtter Posted February 10, 2015 Author Share Posted February 10, 2015 Ok, so I have been playing with this code most of the day now, and can not get the drain at night to not count. Here is my current sanityeffects function:local function sanityeffects(inst, phase) if phase == "day" then inst.components.sanity.dapperness = inst.components.sanity.dapperness - 0.10 inst.components.combat.damagemultiplier = 0.5 elseif phase == "dusk" then inst.components.sanity.dapperness = inst.components.sanity.dapperness + 5 elseif phase == "night" then inst.components.sanity.dapperness = inst.combat.sanity.dapperness + 8 endend@Kzisor Thank you for the help so far.If anyone can help me fix this problem I thank you in advance Link to comment https://forums.kleientertainment.com/forums/topic/50774-tying-a-custom-function-into-another-custom-function/#findComment-611533 Share on other sites More sharing options...
Kzisor Posted February 10, 2015 Share Posted February 10, 2015 @ArashiOtter, you have the wrong code.inst.combat.sanity.dapperness Shouldn't this be components instead of combat? Link to comment https://forums.kleientertainment.com/forums/topic/50774-tying-a-custom-function-into-another-custom-function/#findComment-611535 Share on other sites More sharing options...
ArashiOtter Posted February 10, 2015 Author Share Posted February 10, 2015 Can't believe I missed that ... But on phase change from day to dusk my sanity drain increases, I can not figure out the values to increase it during dusk/night. Link to comment https://forums.kleientertainment.com/forums/topic/50774-tying-a-custom-function-into-another-custom-function/#findComment-611536 Share on other sites More sharing options...
Kzisor Posted February 10, 2015 Share Posted February 10, 2015 @ArashiOtter, You will need to keep playing with it in order to determine how much to add. Check out the tuning.lua file and search for SANITY and it should give you an idea on how much it naturally drains in those periods. Link to comment https://forums.kleientertainment.com/forums/topic/50774-tying-a-custom-function-into-another-custom-function/#findComment-611539 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