Jump to content

Modded character keeps crashing on me


Recommended Posts

27 minutes ago, pickleplayer said:

Hm, then it sounds like somewhere along the line, nightmare fuel has stopped giving him power ups? applyupgrades() will actually run just by logging in too, which is why he randomly says it when joining. (if you're using notepad++, you can highlight the word "applyupgrades" and scroll through the file and see all the other places it's called from)

So maybe something you changed recently broke his ability to eat it.

You can test how far the code gets by throwing in some random prints like  print("test1")  somewhere into oneat() and applyupgrades(). Press Ctrl-L and then eat a nightmare fuel and see which print messages show up. Wherever the print messages stop is wherever the problem is

When i press Ctrl-L in game and then i eat nightmare fuel it doesnt like do anything , that text stays there and does not change , but i put in ''test1'''and it showed up there  

 

Link to comment
Share on other sites

Where did you put it? If its somewhere in oneat(), like under "--give an upgrade" then if you see it, we know that he's still eating it properly and it's still recognized as a food.

If you put a second one like  print("test2") in the local function applyupgrades() somewhere, then if you see it, you know that that part of the code is being run too. But having the speech there for him to say "i am stronger" is just as good as a having print function, so you can just watch to see if he says it instead. Does he still say it when you eat it? If not, the problem must be somewhere between oneat() and the line where the speech text happens.

Link to comment
Share on other sites

oh, sorry, I should have been more specific. when I said put the print lines somewhere in them, I meant inside the actual functions. like line 44 inside oneat() and something like line 20 in applyupgrades()

like this

local function oneat(inst, food)
    if food and food.components.edible and food.components.edible.foodtype == FOODTYPE.NIGHTMAREFUEL then
        --give an upgrade!
        inst.level = inst.level + 1
        applyupgrades(inst) 
	print("test1")  --ANYWHERE INSIDE IT WILL WORK. LIKE THIS. JUST SO WE KNOW IF THIS PART OF THE CODE EVER GETS RUN OR NOT
        inst.SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup")
  end
end

 

And so if he doesn't say anything, then we know applyupgrades()  (lines 20-39) never ran. If it did, he would have talked. So put that print test in oneat like I did up there and then eat a nightmare fuel. If test1 doesn't show up, then the nightmare fuel somehow isnt being eaten properly and something with the foodtype might be off.

Link to comment
Share on other sites

well idk ,   

code:

local function oneat(inst, food)
    if food and food.components.edible and food.components.edible.foodtype == FOODTYPE.NIGHTMAREFUEL then
        --give an upgrade!
        inst.level = inst.level + 1
        applyupgrades(inst) 
        print("test1")      
     inst.SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup")
  end
end

and you have the pic below after i ate 1  , nothing happend... again 

20170910065318_1.jpg

Link to comment
Share on other sites

ok, So that means something is happening where he is not eating it correctly. 

If we look at the if-statement required for him to eat it, it needs to be edible, and its foodtype needs to = nightmarefuel or whatever that means.

This will get into some more advanced troubleshooting with even more print lines. make an extra line after line 43 and put this in there and then eat a nightmare fuel

print("FOOD TEST", food.components.edible, food.components.edible.foodtype == FOODTYPE.NIGHTMAREFUEL, food.components.edible.foodtype, FOODTYPE.NIGHTMAREFUEL)

This will print 4 things (all at once and right next to each other with no spaces)

1. If the food is edible or not (should be true), 2.If the foodtype is the nightmarefuel food type (should be true). If either of those first two things is false, then we will know why it failed. And just for good measure, the last two things it prints are "3.the foodtype of whatever he just ate" and "4.the foodtype of nightmare fuel that you set in modmain" 3 and 4 need to be the same thing. If not, we need to make them the same thing.

speaking of which.... what foodtype did you set nightmare fuel to? I'm suddenly realizing this is actually probably something wrong in the modmain.lua, not hiroki.lua. The 4th print line thing should say what it's set to. And if nothing comes out for the 4th one, it probably wasn't set

Link to comment
Share on other sites

local function oneat(inst, food)
   if food and food.prefab == "nightmarefuel" then
        --give an upgrade!
        inst.level = inst.level + 1
        applyupgrades(inst) 
        print("wubdub1")      
     inst.SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup")
  end
end

like this ?

 

Link to comment
Share on other sites

No no, leave the stuff you already had for the nightmare fuel in the modmain. It still has to be edible (otherwise he wont even try and eat it)

And replace that line with the one I mentioned, (if food and food.prefab == "nightmarefuel" then) so it will look like this.

local function oneat(inst, food)
    if food and food.prefab == "nightmarefuel" then
        --give an upgrade!
        inst.level = inst.level + 1
        applyupgrades(inst)     
	 inst.SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup")
  end
end

 

So you can leave all that FOODTYPE.NIGHTMAREFUEL stuff out of it. I don't work with food items much so I don't know much about it, but you won't need it. Just leave this in the modmain.

AddPrefabPostInit("nightmarefuel",function(inst)
    inst:AddComponent("edible")
    inst.components.edible.healthvalue = 0
    inst.components.edible.sanityvalue = -15
    inst.components.edible.hungervalue = 0
end)

And then try it.

I'm confident this will work.

Link to comment
Share on other sites

I'm sure it doesn't help if we're giving different instructions. Either way should work. Using the FOODGROUP and FOODTYPE would be a better option if you think you might use other items as food later on (since you'd simply assign the FOODTYPE to the new item instead of changing your character file directly). Other than that, I don't think it makes any difference.

--

It seems to me you're copying templates and code snippets without fully understanding what they do. Take a deep look at your mod. Try to understand what every single line of your code does. Feel free to ask if anything isn't clear. Asking is fine and a great way to learn, but you'll be more proficient if you know your code and you'll be able to fix any issue quicker if you understand why any given piece of code is there.

Link to comment
Share on other sites

1 hour ago, alainmcd said:

I'm sure it doesn't help if we're giving different instructions. Either way should work. Using the FOODGROUP and FOODTYPE would be a better option if you think you might use other items as food later on (since you'd simply assign the FOODTYPE to the new item instead of changing your character file directly). Other than that, I don't think it makes any difference.

Woops, I didn't mean to throw it off, my bad for not paying attention. I just thought this one would be easier to understand.

Yea, in the longrun, learning to understand the code first is the most efficient way to get better. But learning such large chunks of code for a food system like that in one go is a very difficult task for someone with very little coding experience. I was like that too, and I also learned to mod by just Frankenstein-ing bits and pieces of code from other parts of the game into the mod, and I learned how they worked by just messing with it and trial and error and being forced to tweak them to fit into place. 

Link to comment
Share on other sites

No problem, we're all here to learn and to contribute with what we know. :)

And I fully agree, it's definitely not necessary to invest a lot of time learning how the game works for simple mods or first efforts. My only nitpick on the matter is with character mods in particular, since it's common for new modders to try and add too much and underestimate the difficulty and scope of their projects. But I think we're on the same page.

Link to comment
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
 Share

×
  • Create New...