Jump to content

Recommended Posts

I really hope somebody can help me with this... So I'm having problems coding with my character... For example I want my character to lose sanity when it hits a butterfly so I wrote this code 

inst:ListenForEvent("onattackother", function(inst, data)
	if victim.prefab == "butterfly" then
	inst.components.talker:Say(GetString(inst, "ANNOUNCE_HIT"))
	inst.components.sanity:DoDelta(-TUNING.SANITY_HUGE)
    end)

but it just keeps crashing and I have no idea of what to do :(... Can someone please enlighten me on what would be the correct way to go about this because I have no idea what's wrong...

I'll be so thankful if someone can help me :)! And thank you for taking some time to read my problem :D!!

Link to comment
https://forums.kleientertainment.com/forums/topic/67298-help-with-coding-question/
Share on other sites

16 minutes ago, SuperDavid said:

Can someone please enlighten me on what would be the correct way to go about this because I have no idea what's wrong...

Wrong syntax. END is missing for the IF. Game crash.

Also victim is nil. So victim.prefab crashes the game.

The event doesn't event have a victim entry on that data table incoming.

	inst:ListenForEvent("onattackother", function(inst, data)
		if data.target.prefab == "butterfly" then
			inst.components.talker:Say(GetString(inst, "ANNOUNCE_HIT"))
			inst.components.sanity:DoDelta(-TUNING.SANITY_HUGE)
		end
	end)

Should be this.

You will need a ANNOUNCE_HIT entry on your character's speech or it will read "UNKNOWN STRING".

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...