Jump to content

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 ! ' ^ '

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

Edited by Mobbstar

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 !

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...