Jump to content

Carnivore - old vs new code + checking ROG enabled - issue


Recommended Posts

Hello,

I'll try to be short here. There is part of the code:

 

character.lua

--Food
local eater = inst.components.eater
eater:SetCarnivore(true)
eater.ignoresspoilage = true
 
changed into:
--Food
local eater = inst.components.eater
eater:SetDiet({ FOODGROUP.OMNI }, { FOODTYPE.MEAT })
eater.ignoresspoilage = true
 
and the error it gave me is:
71: attempt to call method 'SetDiet' (a nil value)
 
Additional questions: 

1. Do I need ROG-enabled checking code or not at all? 

2. Are those parts of code in correct lua now? Or that should be changed as well?

 
sorry if that's stupid... And yea, I've read forums about food types, but guess I'm just blind if there was an answer 
 
 
 
 
 
Link to comment
Share on other sites

if TUNING.LIGHTNING_GOAT_DAMAGE then--RoG codeelse--non-RoG codeend

 

 

so something like this?

--Foodif local eater = inst.components.eater theneater:SetDiet({ FOODGROUP.OMNI }, { FOODTYPE.MEAT })elseeater:SetCarnivore(true)eater.ignoresspoilage = true 

what about ignoressspoilage? Rewrite under "SetDiet" as well? 

I guess the 2nd line of the code is wrong -.- ... 

Link to comment
Share on other sites

local eater = inst.components.eaterif TUNING.LIGHTNING_GOAT_DAMAGE then    --RoG code    eater:SetDiet({ FOODGROUP.OMNI }, { FOODTYPE.MEAT })else    --non-RoG code    eater:SetCarnivore(true)endeater.ignoresspoilage = true

Edited by Maris
Link to comment
Share on other sites

if TUNING.LIGHTNING_GOAT_DAMAGE then     --RoG code     eater:SetDiet({ FOODGROUP.OMNI }, { FOODTYPE.MEAT }

 

Oh.. ok... I'm stupid still.. what does Lightning goat has to do with it? Just an info... O.o 

Link to comment
Share on other sites

what does Lightning goat has to do with it?

 

There aren't goats in DST without the RoG branch, so TUNING.LIGHTNING_GOAT_DAMAGE returns nil, which makes the if (nil gets evaluated like false) go to the non-RoG code. With the RoG branch, goats exist, the tuning value exists, a number gets returned, which makes the if (a number gets evaluated to true) go to the RoG code.

Link to comment
Share on other sites

There aren't goats in DST without the RoG branch, so TUNING.LIGHTNING_GOAT_DAMAGE returns nil, which makes the if (nil gets evaluated like false) go to the non-RoG code. With the RoG branch, goats exist, the tuning value exists, a number gets returned, which makes the if (a number gets evaluated to true) go to the RoG code

 

Ooo I get it now. Thank you :)

Link to comment
Share on other sites

local eater = inst.components.eater   if TUNING.LIGHTNING_GOAT_DAMAGE then     --RoG code     eater:SetDiet({ FOODGROUP.OMNI }, { FOODTYPE.MEAT }) else     --non-RoG code     eater:SetCarnivore(true) end   eater.ignoresspoilage = true

 

Now error is related to this:

 

74: function arguments expected near '<'

LUA ERROR stack traceback:
        =[C] in function 'assert'
        scripts/mainfunctions.lua(92,1)
        =(tail call) ?
 
where line 74 is:
eater:Set<span class="searchlite">Carnivore</span>(true)
 
Link to comment
Share on other sites

where line 74 is:

eater:Set<span class="searchlite">Carnivore</span>(true)

That searchlite <span> element is an artifact introduced by the forums' search feature. You'll need to remove all of that. It should just be SetCarnivore (true).

 

edit: typos, eww

Edited by Corrosive
Link to comment
Share on other sites

You should learn at least basics of lua, to understand what are you doing in general.

 

I must say I read tutorials, lua-wikis, guides etc. Still it's NOT my world. maybe you guys won't understand but I'm not the type of person who loves sitting by informatic-rubbish. That's why I'm asking..

 

And - back to the beginning -

element is an artefact introduced by the forums' search feature. You'll need to remove all of that. It should just be SetCarnivore (true).

 

I STARTED from carnivore. But carnivore doesn't work anymore.

Link to comment
Share on other sites

@Foxrai,
 
I think you completely missed the point of what I was saying =o
 
You said that line 74 of your code was:

 

eater:Set<span class="searchlite">Carnivore</span>(true)

 
That implies that you copy/pasted that code from the forums.  There is a bug in the forums in which if you search for a term, the word highlighter tries to highlight words INSIDE of code blocks by inserting an HTML element around the search term.

 

Outside of code blocks, those search term highlighter elements are normally invisible, but since code blocks are inside of a <pre> (pre-formatted text) HTML tag, the <span> HTML element is not treated as HTML, but rather as part of the code.

 

As such, when you copied the code, you also inadvertently copied some HTML that was injected by the search highlighter, which will wreak havoc when it pops up in the middle of actual Lua code.

 

Link to comment
Share on other sites

Indeed ._. ow well... non-DST versions kinda went well and working fine... DST is just eww D: too many changes!!

 

and Corrosive - 

- nothing more to say than:   oooooOOO! got it! triple checking next time -.-

Edited by Foxrai
Link to comment
Share on other sites

Just by suggest.
Use a program like notepad ++ when you are cheking code. This program detects what kind of code are you writting and uses colors for mark parts of the same code, as well, it uses color for highlight errors in those codes xD...

And if you are the kind of person whoi dont get nothing from programing tutorial, I suggest you to continuing reading codes you are writting, so you will learn what are you writting (like a lenguage :D)

Good luck :)

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