Jump to content

[Question] ISFarmingInfo.lua: "__le not defined for operand"


Furious_Monk

Recommended Posts

Hey everyone,

 

Sorry if this is too little info to help me on, but I have a question about a mod I am trying to get working that modifies different parts of the Farming folder's lua files in the Client and Server folders. It may help to know that I am trying to add a "Compost" action to plants, and I have done this by simply copying/changing any instance of the "Fertilizer" actions that I can find.

 

I have had it working in various stages. At first, I somehow killed the farming info panel, and couldn't see any information about a plant. I got that fixed by commenting out my text coloring function:

 

function ISFarmingInfo.getCompostColor(info)    if info.plant.state ~= "dry" or info.plant.state ~= "rotten" or info.plant.state ~= "destroyed" then        if(info.plant.compost <= 2) then            ISFarmingInfo:getGreen(compost_rgb, nil);        elseif(info.plant.compost > 2 and info.plant.compost <= 4) then            ISFarmingInfo:getOrange(compost_rgb, nil);        else            ISFarmingInfo:getRed(compost_rgb, nil);        end    else        ISFarmingInfo:getWhite(compost_rgb, nil);    endend

 

It was nice to see the panel back, but it still wasn't updating any kind of state on the plant's Compost level (which is drawn after "Fertilizer" in the info panel). I went through and did some fixes where I could with draw locations, and I was thinking I had it figured out, but alas, as long as that code section is uncommented, the console pings 100 exceptions per second, refering directly to the first line of the second if() statement:

 

if(info.plant.compost <=2) then

 

as well as this line called in the function ISFarmingInfo:render() up above:

 

ISFarmingInfo.getCompostColor(self);

 

Here is the Stack Trace:

 

-----------------------------------------STACK TRACE-----------------------------------------function: getCompostColor -- file: ISFarmingInfo.lua line # 493function: render -- file: ISFarmingInfo.lua line # 60java.lang.RuntimeException: __le not defined for operand    at se.krka.kahlua.vm.KahluaUtil.fail(KahluaUtil.java:91)    at se.krka.kahlua.vm.KahluaThread.luaMainloop(KahluaThread.java:876)    at se.krka.kahlua.vm.KahluaThread.call(KahluaThread.java:163)    at se.krka.kahlua.vm.KahluaThread.pcall(KahluaThread.java:1727)    at se.krka.kahlua.vm.KahluaThread.pcallvoid(KahluaThread.java:1687)    at se.krka.kahlua.integration.LuaCaller.pcallvoid(LuaCaller.java:38)    at zombie.ui.UIElement.render(UIElement.java:1156)    at zombie.ui.UIElement.render(UIElement.java:1149)    at zombie.ui.UIManager.render(UIManager.java:618)    at zombie.gameStates.IngameState.renderframeui(IngameState.java:791)    at zombie.gameStates.IngameState.render(IngameState.java:916)    at zombie.gameStates.GameStateMachine.render(GameStateMachine.java:37)    at zombie.GameWindow.render(GameWindow.java:685)    at zombie.GameWindow.run(GameWindow.java:1193)    at zombie.GameWindow.maina(GameWindow.java:991)    at zombie.gameStates.MainScreenState.main(MainScreenState.java:168)

 

Specifically, I am wondering what that __le not defined for operand is refering to, as well as any advice you can give about what I might be doing wrong to cause the info panel to not work.

 

In case you can't tell, I don't really know what I'm doing with anything too in depth with code, though lua seems to be easier for me to understand. It is hard to know where things are going wrong if you aren't writing the whole thing yourself. Any help would be much appreciated, and thank you!

Link to comment
Share on other sites

__le refers to a metamethod in Lua. To be more specific it is the metamethod for (less or equal). You can find more info here: http://www.lua.org/pil/13.2.html

Basically what Lua is telling you here is that you are trying to compare something with less or equal which can't be compared like that. What type is the variable you are storing in info.plant.compost?

Link to comment
Share on other sites

Thanks for the fast reply, RoboMat! Er... it's an integer, isn't it? I wonder where that would be defined. lua seems to require no definitions! I mean, obviously it does, but I don't know where it is calling this information from. I am running exactly the same thing as that for the info.plant.fertilizer, so maybe you would know where THAT is getting defined?

 

I went through all the files I could find to find any instance of fertilize being used, and I thought I got everything, but I guess I am missing a definition somewhere.

 

Could it be related to the item usage? I have noticed that when I use my compost item, it does not "drain" as it should, but I figured I would address that problem later.

Link to comment
Share on other sites

Thanks for the fast reply, RoboMat! Er... it's an integer, isn't it? I wonder where that would be defined. lua seems to require no definitions! I mean, obviously it does, but I don't know where it is calling this information from. I am running exactly the same thing as that for the info.plant.fertilizer, so maybe you would know where THAT is getting defined?

Lua doesn't have type definitions. Every variable can carry any type. Add this line to your code right in front of the faulty if statement and see what it says in the console:

print(type(info.plant.compost))
I'm afraid I can't say much about the other stuff without digging deeper into the code.
Link to comment
Share on other sites

Well, I am not sure if this helps, but I have a different exception when I try to actually add Compost to a plant:

 

Console Stack Trace:

-----------------------------------------STACK TRACE-----------------------------------------function: compost -- file: basicFarming.lua line # 115function: perform -- file: ISCompostAction.lua line # 35java.lang.RuntimeException: __lt not defined for operand    at se.krka.kahlua.vm.KahluaUtil.fail(KahluaUtil.java:91)    at se.krka.kahlua.vm.KahluaThread.luaMainloop(KahluaThread.java:876)    at se.krka.kahlua.vm.KahluaThread.call(KahluaThread.java:163)    at se.krka.kahlua.vm.KahluaThread.pcall(KahluaThread.java:1727)    at se.krka.kahlua.vm.KahluaThread.pcall(KahluaThread.java:1642)    at se.krka.kahlua.integration.LuaCaller.pcall(LuaCaller.java:72)    at zombie.characters.CharacterTimedActions.LuaTimedActionNew.perform(LuaTimedActionNew.java:74)    at zombie.characters.IsoGameCharacter.update(IsoGameCharacter.java:8667)    at zombie.characters.IsoPlayer.update(IsoPlayer.java:2708)    at zombie.iso.IsoCell.ProcessObjects(IsoCell.java:1336)    at zombie.iso.IsoCell.update(IsoCell.java:5164)    at zombie.iso.IsoWorld.update(IsoWorld.java:2354)    at zombie.gameStates.IngameState.update(IngameState.java:1216)    at zombie.gameStates.GameStateMachine.update(GameStateMachine.java:101)    at zombie.GameWindow.logic(GameWindow.java:636)    at zombie.GameWindow.run(GameWindow.java:1187)    at zombie.GameWindow.maina(GameWindow.java:991)    at zombie.gameStates.MainScreenState.main(MainScreenState.java:168)

Here are the relevent code snippets, with lines that the console tagged in red:

 

From: basicFarming.lua: Line 4 - if plant.compost < 5  then

 

1. -- add compost to the plant2. function basicFarming.compost(compost, plant)3.     if plant.state ~= "plow" and plant:isAlive() then4.         if plant.compost < 5  then5.             plant.compost = plant.compost + 16.             plant.nextGrowing = plant.nextGrowing - 207.             if plant.nextGrowing < 1 then8.                 plant.nextGrowing = 19.             end10.        else -- too much compost and our plant may get flies !11.            basicFarming.flies(plant)12.        end13.        basicFarming.saveData(plant)14.    end15. end

 

From: ISCompostAction.lua: Line 9 - basicFarming.compost(self.item, self.plant)

 

1. function ISCompostAction:perform()2.     self.item:getContainer():setDrawDirty(true);3.     self.item:setJobDelta(0.0);4.     if isClient() then5.         local sq = self.plant:getSquare()6.         local args = { x = sq:getX(), y = sq:getY(), z = sq:getZ() }7.         sendClientCommand(self.character, 'farming', 'compost', args)8.     else9.         basicFarming.compost(self.item, self.plant)10.    end11.    -- MP shouldn't do this directly12.    self.item:Use()13.    self.character:getInventory():Remove("CompostEmpty")14.    -- needed to remove from queue / start next.15.    ISBaseTimedAction.perform(self);16. end
Link to comment
Share on other sites

Hey Robert! Thanks for answering.

 

Yes, you are correct. I was not ever defining a number var for plant.compost OR info.plant.compost in the ISFarmingInfo.lua file. I wound up hacking it with:

    --Hack to stop compost from being set to nil    if plant.compost == nil then        plant.compost = 0    end

...in the basicFarming.lua function, but I haven't done anything for info.plant.compost. I think what you are suggesting (editing the ISPlant.lua) has already been done just by virtue of me copying every instance of the "fertilizer" stuff. I have a o.compost = 0 in the ISPlant:new function, an ISPlant:addCompost(amount) function, and a self.compost = modData.compost (and a call to reset modData for that result).

 

I don't quite know how its working right now, but I am only able to see the information in the farming panel now AFTER I have composted the plant. It also calls an __lt error on that info.plant.compost if I don't compost it first.

 

SO IN SHORT!!!

Do you think it is just because I used it on plants that I had made in a game save from before I added the mod? If so... I feel like an idiot! I could have had this finished hours and hours ago hahahha.

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
×
×
  • Create New...