Sign in to follow this  
AkaiNight

OnEat code is not working

Recommended Posts

AkaiNight    14

I'm using this code for when eat something not "fish or cooked fish or ice or fishsticks or fish tacos" gives 5 hunger and -10 sanity

 

 elseif food and food.components.edible and food.prefab  == not "ice" or "fish_cooked" or "fish" or "fishtacos" or "fishsticks" or then
    local hungerboost = 5
    local sanityboost = -10
    
    local foodcheck = food.inst.prefab == "spoiled_food" and 0 or hungerboost

    inst.components.health:DoDelta(0) 
    inst.components.sanity:DoDelta(0) 
    inst.components.hunger:DoDelta(5 - food:GetHunger() * eater.hungerabsorption)
    inst.components.talker:Say("I shouldn't eat that. Nya~")
end

but when i eat something it crash. lost server connection.

Share this post


Link to post
Share on other sites
20 minutes ago, AkaiNight said:

I'm using this code for when eat something not "fish or cooked fish or ice or fishsticks or fish tacos" gives 5 hunger and -10 sanity

 


 elseif food and food.components.edible and food.prefab  == not "ice" or "fish_cooked" or "fish" or "fishtacos" or "fishsticks" or then
    local hungerboost = 5
    local sanityboost = -10
    
    local foodcheck = food.inst.prefab == "spoiled_food" and 0 or hungerboost

    inst.components.health:DoDelta(0) 
    inst.components.sanity:DoDelta(0) 
    inst.components.hunger:DoDelta(5 - food:GetHunger() * eater.hungerabsorption)
    inst.components.talker:Say("I shouldn't eat that. Nya~")
end

but when i eat something it crash. lost server connection.

Even if the game crashes you should still be getting an error log. You can go to MyDocuments/Klei/DontStarveTogether and I think it's called clientlog.txt. Do you have the rest of the function this is in? I'm seeing food being used instead of inst here which might be why you're getting errors, just a guess from what I see.

Share this post


Link to post
Share on other sites
AkaiNight    14

Here is the full code 

--Restat for foods
local function oneat(inst, food)	

	if food and food.components.edible and food.prefab == "fishsticks" then
	       inst.components.health:DoDelta(50)
		inst.components.sanity:DoDelta(50)
		inst.components.hunger:DoDelta(50)
		inst.components.talker:Say("Itadakimasu. Nya~", 1.2, true)
	
	elseif food and food.components.edible and food.prefab == "fishtacos" then
	       inst.components.health:DoDelta(50)
		inst.components.sanity:DoDelta(50)
		inst.components.hunger:DoDelta(50)
		inst.components.talker:Say("Itadakimasu. Nya~", 1.2, true)
	
	elseif food and food.components.edible and food.prefab == "fish" then
		inst.components.health:DoDelta(20)
		inst.components.sanity:DoDelta(30)
		inst.components.hunger:DoDelta(20)
		inst.components.talker:Say("Itadakimasu. Nya~", 1.2, true)
	
	elseif food and food.components.edible and food.prefab == "fish_cooked" then
		inst.components.sanity:DoDelta(-15)
		inst.components.talker:Say("Don't you know the fire is not good for me! Do not try to eat that me again!!!. Nya~", 1.2, true)
	
       elseif food and food.components.edible and food.prefab == "ice" then
	       inst.components.health:DoDelta(5)
		inst.components.sanity:DoDelta(10)
		inst.components.talker:Say("Itadakimasu. Nya~", 1.2, true)

      elseif food and food.components.edible and food.prefab  == not "ice" or "fish_cooked" or "fish" or "fishtacos" or "fishsticks" then
    local hungerboost = 5
    local sanityboost = -10
    
    local foodcheck = food.inst.prefab == "spoiled_food" and 0 or hungerboost

    inst.components.health:DoDelta(0) 
    inst.components.sanity:DoDelta(0) 
    inst.components.hunger:DoDelta(5 - food:GetHunger() * eater.hungerabsorption)
    inst.components.talker:Say("I shouldn't eat that. Nya~")
end

	end
end

and i'll try to find clentlog.txt but i remember like there is no error in it but not sure let me check it.

 

 

here is the log's last lines 

 

[00:08:57]: ModIndex: Load sequence finished successfully.    
[00:08:57]: Reset() returning
[00:08:59]: Attempting to send resume request
[00:09:01]: ReceiveResumeNotification
[00:09:01]: Movement prediction enabled    
[00:09:01]: WARNING! Could not find region 'FROMNUM' from atlas 'FROMNUM'. Is the region specified in the atlas?
[00:09:01]: Looking for default texture 'FROMNUM' from atlas 'FROMNUM'.
[00:09:02]: Deserializing tile data (450 x 450)
[00:09:02]: Could not load mod_config_data/modconfiguration_workshop-842702425_FULL    
[00:09:16]: SendRemoteExecute(", -100.849693, 176.360687)
[00:09:16]: SendRemoteExecute(, -91.980110, 177.573227)
[00:09:31]: [Error] Dedicated server process terminated prematurely.
[00:09:37]: Connection lost to 127.0.0.1|10999 <4454978858943124495>
[00:09:37]: [Connect] PendingConnection::Reset(true)
[00:09:37]: PushNetworkDisconnectEvent With Reason: "ID_CONNECTION_LOST", reset: true
[00:09:37]: [IPC] Unregistering handler for signal #0000087C
[00:09:37]: [IPC] Unregistering handler for signal #00000910
[00:09:37]: [IPC] Unregistering handler for signal #00000914
[00:09:37]: [IPC] Unregistering handler for signal #00000918
[00:09:37]: [IPC] Unregistering handler for signal #0000091C
[00:09:37]: [IPC] Sending signal... #00000924
[00:09:39]: [IPC] Unregistering handler for signal #000008E4
[00:09:39]: [IPC] Unregistering handler for signal #000008D8
[00:09:39]: [IPC] Unregistering handler for signal #00000900
[00:09:39]: [IPC] Unregistering handler for signal #000008F8
[00:09:39]: [IPC] Unregistering handler for signal #0000090C
[00:09:39]: Serializing user: session/04C57B1F55D8BE19/A7NJO8FMA1JL/0000000001
[00:09:39]: [Steam] Game Connection terminated (16777343|10999)
[00:09:39]: [Shard] Stopping shard mode
[00:09:39]: ModWorkshop::CancelDownloads clearing all unfinished downloads

Edited by AkaiNight

Share this post


Link to post
Share on other sites
3 minutes ago, AkaiNight said:

I did it before this crash.

If you're running the game with caves enabled I would create a new world without caves, I was running into a similar issue where an error wouldn't generate, but instead would completely shut down the game/freeze.

Share this post


Link to post
Share on other sites
AkaiNight    14
1 minute ago, RedHairedHero said:

If you're running the game with caves enabled I would create a new world without caves, I was running into a similar issue where an error wouldn't generate, but instead would completely shut down the game/freeze.

Ah forgive me. When i said it's crash i mean the server is closing. Sorry my bad.

Share this post


Link to post
Share on other sites
Lumina    2149

If you play with caves enabled, or in a dedicated server, you have client log and server log. Sometimes the client log has nothing useful on it, when the server log has more information.

 

 

See here for path examples.

Share this post


Link to post
Share on other sites
AkaiNight    14
Just now, RedHairedHero said:

I feel like this line in particular may be a problem.


local foodcheck = food.inst.prefab == "spoiled_food" and 0 or hungerboost

What was it you were looking to use foodcheck for?

Well i found it now too. I found the error in server.log thanks a lot it seems like i just need to delete "inst". 

Share this post


Link to post
Share on other sites
6 minutes ago, Lumina said:

If you play with caves enabled, or in a dedicated server, you have client log and server log. Sometimes the client log has nothing useful on it, when the server log has more information.

 

 

See here for path examples.

I'll have to remember this for future debugging. Thanks for the hot tip.

Share this post


Link to post
Share on other sites
Lumina    2149

Glad it helps :) Yeah, i got troubles at first when searching for errors and got nothing in client log until i discovered server log. Some rares errors could lead to have no error, neither in client or server log, but they are pretty rare.

 

And it's really important to test a mod as a client (meaning, either dedicated server or server with caves), so server logs are really useful for this.

Share this post


Link to post
Share on other sites
AkaiNight    14
1 minute ago, RedHairedHero said:

I only just started using the debug keys and it makes testing so much easier, wish I thought about them when I first started.

Debug keys? What are they? Can ı use them too? Is there any guide for it?

Share this post


Link to post
Share on other sites
GLOBAL.CHEATS_ENABLED = true
GLOBAL.require('debugkeys')

Just pop this into your modmain when you need to use it. And be sure to comment it out or remove it before you release it.

The couple shortcuts I use are Ctrl+R to reload your scripts instantly and perform a soft reset.

And you can press G to go into godmode.

There's a lot more keys you can find in the debugkeys lua file.

Edited by RedHairedHero

Share this post


Link to post
Share on other sites
AkaiNight    14
Just now, RedHairedHero said:

GLOBAL.CHEATS_ENABLED = true
GLOBAL.require('debugkeys')

Just pop this into your modmain when you need to use it.

The couple shortcuts I use are Ctrl+R to reload your scripts instantly and preform a soft reset.

And you can press G to go into godmode.

There's a lot more keys you can find in the debugkeys lua file.

It seems like very useful thanks a lot.

Share this post


Link to post
Share on other sites
Lumina    2149
9 hours ago, RedHairedHero said:

The couple shortcuts I use are Ctrl+R to reload your scripts instantly and perform a soft reset.

What is a soft reset ? Meaning that if you add a line to a script you just have to do this and not restarting the game and all ?

Share this post


Link to post
Share on other sites
11 hours ago, Lumina said:

What is a soft reset ? Meaning that if you add a line to a script you just have to do this and not restarting the game and all ?

Exactly, soft reset means it just restarts the game from the start of the day.

Share this post


Link to post
Share on other sites
Lumina    2149

Wow. Nice to know.

My main problem is more crash and having to restart the game rather than need for soft reset but still, could be very useful. Thanks :)

Share this post


Link to post
Share on other sites

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
Sign in to follow this