Jump to content

[Help] Function doesn't do anything


Hitokage

Recommended Posts

Hi everyone ! I'm new here ! :3

 

I create a mod (here : http://steamcommunity.com/sharedfiles/filedetails/?id=317388877)

and actually I'm really lost with the code.

 

I try a lot of things, and I always get a crash.

 

But finally when it seems to work... it doesn't do anything ! X3

 

This his the code (in scripts/prefabs/rlu.lua) :

(the locomotor's values are huge to "see" a change)

local function auralevel(inst)	local locomotor_walk = 3.85	local locomotor_run = 5.75	if inst.strength == "med" then		locomotor_walk = 14.15		locomotor_run = 16.05	elseif inst.strength == "high" then		locomotor_walk = 24.45		locomotor_run = 26.35	end		inst.components.locomotor.walkspeed = locomotor_walk	inst.components.locomotor.runspeed = locomotor_run	endlocal function onhealthchange(inst, data)	if inst.strength == "high" then		if inst.components.health.current > 50 then			inst.strength = "med"			inst.components.talker:Say("High to Med")		end			elseif inst.strength == "low" then		if inst.components.health.current < 100 then			inst.strength = "med"			inst.components.talker:Say("Low to Med")		end			else		if inst.components.health.current < 55 then			inst.strength = "high"			inst.components.talker:Say("Med to Low")		elseif inst.components.health.current > 105 then			inst.strength = "low"			inst.components.talker:Say("Med to High")		end	end	auralevel(inst)endlocal fn = function(inst)	-- Voice Sound	inst.soundsname = "willow"		-- Minimap Icon	inst.MiniMapEntity:SetIcon( "riolu.tex" )		-- Riolu Stats		inst.strength = "low"		inst.components.health:SetMaxHealth(150)	inst.components.health.current = 150	auralevel(inst)		inst.components.hunger:SetMax(150)	inst.components.hunger.current = 150		inst.components.sanity:SetMax(300)	inst.components.sanity.current = 300		inst.components.sanity.night_drain_mult = 0.5	inst.components.sanity.neg_aura_mult = 0.5		inst:ListenForEvent("healthdelta", onhealthchange)	end

What is wrong ? Why it doesn't do anything ?!

Thank you in advance for your answer ! ' ^ '

Link to comment
Share on other sites

Next time you have a problem like this, try debugprinting. Just use the function print() and put something in the brackets.

 

e.g. print("high to low",inst.components.health.current)

 

in the log (log.txt file or ctrl + L) it should say: ../some/weird/path/prefab.lua high to low

since current doesn't show up, it's safe to assume it doesn't exist. With the right name the line should be:

../some/weird/path/prefab.lua high to low     42

Link to comment
Share on other sites

Finally ! It's the "inst.components.health.currenthealth" ! It works now ! * ^^^ *

 

Thanks you so much ! ^ w ^

 

Sanity and Hunger just use "current" so I had never noticed that. I only see it with the ":SetMax" by chance X3

 

And thanks for the log advice. I already use it with the mod debug in modsettings to understand crash, but never with the "print" command directly.

 

Huge thanks again !

Link to comment
Share on other sites

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.

×
  • Create New...