Jump to content

Modded character keeps crashing on me


Recommended Posts

6 hours ago, alainmcd said:

Add


inst.level = 0

to your master_postinit before calling applyupgrades(inst). You'll also want to save your inst.level with an onsave function and to apply it correctly with an onpreload function. Look at wx78.lua.

Thanks a lot ! 

Link to comment
Share on other sites

What do you mean by "nothing happens"? Still crashing, doesn't load, ...?

From your code I imagine that upgrades are indeed applied, but they aren't saved and loaded correctly. Your onsave and onpreload functions aren't referenced or called from anywhere, you need to add

inst.OnSave = onsave
inst.OnPreLoad = onpreload

at the end of your master_postinit.

Link to comment
Share on other sites

16 minutes ago, alainmcd said:

What do you mean by "nothing happens"? Still crashing, doesn't load, ...?

From your code I imagine that upgrades are indeed applied, but they aren't saved and loaded correctly. Your onsave and onpreload functions aren't referenced or called from anywhere, you need to add


inst.OnSave = onsave
inst.OnPreLoad = onpreload

at the end of your master_postinit.

imma try this , sometimes nothing happens or crashes when i load the world , i tried adding  you on stream btw , we can talk easier...

Edited by Franke004
Link to comment
Share on other sites

15 minutes ago, Franke004 said:

And now it randomly crashed while i was playing

You have to read your crash log:

Quote

[string "../mods/hiroki/scripts/prefabs/hiroki.lua"]:52: attempt to compare number with nil

Line 52 of your mod tries to call an inst.charge_time that isn't declared. I see no purpose for that line.

25 minutes ago, Franke004 said:

Now it does not crash , but nothing happens , it does not upgrade ;-;

Does the character say "More power... " when you eat nightmare fuel or "THE THIRST HAS BEEN QUENCHED!!" if you keep eating?

Link to comment
Share on other sites

In line 42 you are checking if whatever your character eats is of a NIGHTMAREFUEL food type:

Quote

food.components.edible.foodtype == FOODTYPE.NIGHTMAREFUEL

You need to have declared the food type and given the nightmare fuel the correct food type, something like this in your modmain.lua:

GLOBAL.FOOTYPE.NIGHTMAREFUEL = "NIGHTMAREFUEL"

AddPrefabPostInit("nightmarefuel", function(inst)
	inst:AddComponent("edible")
	inst.components.edible.foodtype = GLOBAL.FOODTYPE.NIGHTMAREFUEL
end)

I imagine you already have at least some of that (like inst:AddComponent("edible") to make nightmare fuel edible).

Link to comment
Share on other sites

This is what i had going , imma add what u said aswell , 
 

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

end)

I added the stuff in that u sent me  , maybe now it works , im gonna try

Link to comment
Share on other sites

''An error has occured. Check your logs for details'' when i try to join the world..   this is what the logs say

[00:00:31]: [string "../mods/hiroki/modmain.lua"]:59: variable 'FOOTYPE' is not declared

line 59: GLOBAL.FOOTYPE.NIGHTMAREFUEL = "NIGHTMAREFUEL"

Link to comment
Share on other sites

4 minutes ago, Franke004 said:

''An error has occured. Check your logs for details'' when i try to join the world..   this is what the logs say

[00:00:31]: [string "../mods/hiroki/modmain.lua"]:59: variable 'FOOTYPE' is not declared

line 59: GLOBAL.FOOTYPE.NIGHTMAREFUEL = "NIGHTMAREFUEL"

You misspelled "foodtype." Heh, happens to the best of us.

Link to comment
Share on other sites

Let's see, He says "more power" after he eats, right? So we know that applyupgrades() is running when you eat it. In this line 26 "inst.components.hunger.max = math.ceil (75 + upgrades * 10)"   Do you know what "upgrades" is? I'm not exactly sure, I don't see where it's coming from, but also apparently it isn't crashing it. But it could have something to do with it.

Try working backwards and take some smaller steps first to get something small to work, and then work your way up from there. if you change it to just "inst.components.hunger.max = 10"  then does it work? If it doesn't, go back into something simpler and see if that works. If it does, start adding in the missing parts bit by bit until you find what's causing the problem.

-Oh also, just to test, try eating something random after the upgrade happens to see if the hunger bar just needed to update. I've had problems like that in the past

Link to comment
Share on other sites

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

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