incognitox Posted February 7, 2015 Share Posted February 7, 2015 (edited) Hey Guys, i'm making a character, and when he eat a seed(just for test), he gain speed move, but i can't set a time for the buff, he gain infinite speed, and i want a temporary gain, i can't make the time in buff, i try to use the looping "for" and "while" but don't work in DST In Cmd works fine the looping making a timer, but in DST don't, here's my code: i try use like this in cmd using just .lua : -- This make the count, making 20sec in the cmd, if u guys wanna test for i = 20000, 0, -1 do print(i) if i > 0 then print("buff") end if i == 0 then print("normal") endendprint("end") after i try something like this using while, another time in cmd, and works fine, but fail in the DST for i = 20000, 0, -1 do while i > 0 doprint(i)i = 1- i if i == 0 thenprint("parei")endend endprint("end") -----------------------------------So, here's my code local function OnEat(inst,food) if food.components.edible and food.components.edible.foodtype == "SEEDS" then --edible food has these types too for i = 20000, 0, -1 do while i > 0 do inst.components.locomotor.runspeed = 15 i = 1 - i if i == 0 then inst.components.locomotor.runspeed = 5 end end end end end ...... -- This initializes for the host onlylocal master_postinit = function(inst)-- choose which sounds this character will playinst.soundsname = "wilson"-- Stats inst.components.health:SetMaxHealth(150)inst.components.hunger:SetMax(100)inst.components.sanity:SetMax(200) inst.components.builder.science_bonus = 1 -- Velocidade em 10 quando tomar café inst:AddComponent("eater") inst.components.eater:SetOnEatFn(OnEat) end If u guys can help me, i appreciate ^-^ Edited February 7, 2015 by incognitox Link to comment https://forums.kleientertainment.com/forums/topic/50647-modding-char-help/ Share on other sites More sharing options...
Mobbstar Posted February 7, 2015 Share Posted February 7, 2015 I assume your problem is that the loop doesn't run parallel to game ticks. You shouldn't use loops for that kind of stuff in Don't Starve. I don't know if this behaves any special in DST, but in DS there are special methods scattered around various utility files. For example, you can use the following:inst:DoTaskInTime(time,function,arguments_other_than_inst)If you want the time to be long, you may need to set "onsave" and "onload" functions to keep the temporary effects saved. Shorter timespans are insignificant and not worth the effort. Link to comment https://forums.kleientertainment.com/forums/topic/50647-modding-char-help/#findComment-610707 Share on other sites More sharing options...
incognitox Posted February 9, 2015 Author Share Posted February 9, 2015 I assume your problem is that the loop doesn't run parallel to game ticks. You shouldn't use loops for that kind of stuff in Don't Starve. I don't know if this behaves any special in DST, but in DS there are special methods scattered around various utility files. For example, you can use the following:inst:DoTaskInTime(time,function,arguments_other_than_inst)If you want the time to be long, you may need to set "onsave" and "onload" functions to keep the temporary effects saved. Shorter timespans are insignificant and not worth the effort.Thx man, my function works now, i make that local function OnEat(inst,food) if food.components.edible and food.components.edible.foodtype == "SEEDS" then --edible food has these types too inst.components.locomotor.runspeed = 12 inst:DoTaskInTime(30, function(inst) inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED end) end end Link to comment https://forums.kleientertainment.com/forums/topic/50647-modding-char-help/#findComment-611329 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