greatguys Posted March 19, 2015 Share Posted March 19, 2015 (edited) In my previous thread, I was having trouble adjusting the inventory size of the lureplant. It would give me an error. After investigating in the inventory component, I noticed a function that would return the max size of the inventory. I threw that in my modmain and it works as it should, but I don't know why. When the error would happen, it would say:[string "scripts/components/inventory.lua"]:615: attempt to compare number with string Well, okay, I go in the inventory components and go to line 615 if slot then local olditem = self:GetItemInSlot(slot) can_use_suggested_slot = slot ~= nil and slot <= self.maxslots and ( olditem == nil or (olditem and olditem.components.stackable and olditem.prefab == inst.prefab)) and self:CanTakeItemInSlot(inst,slot) --line 615 end Maybe the quotes in the config data is screwing it up. I delete the quotes, and still the error.I go back into the inventory component, ctrl+f "maxslots", and find the function. The function is:function Inventory:GetNumSlots() --line 301 return self.maxslotsend I go into my modmain, call the function after the maxslots was modified, run the game- and it works. But on line 615 its got the maxslots and I guess interpretedit as a string before the function was called? Why does the function need to be called? What is return doing exactly? Edited March 19, 2015 by greatguys Link to comment https://forums.kleientertainment.com/forums/topic/52169-returns-are-throwing-me-off/ Share on other sites More sharing options...
Kzisor Posted March 19, 2015 Share Posted March 19, 2015 (edited) @greatguys, please post your full code so we can look at it. More than likely you are using quotations around an integer that you don't need to be using. Example:local i = "1"andlocal i = 1The first is a string and the second is a number. Make sure when you are setting integers to not use quotations; this includes values coming from the configuration_options in the modinfo.lua file. Edited March 19, 2015 by Kzisor Link to comment https://forums.kleientertainment.com/forums/topic/52169-returns-are-throwing-me-off/#findComment-623036 Share on other sites More sharing options...
greatguys Posted March 20, 2015 Author Share Posted March 20, 2015 (edited) My modinfo.luaconfiguration_options ={ { name = "timer", label = "Digestion Time", --Remember commas options = { {description = "20 Secs.", data = "20"}, {description = "1 Minute", data = "60"}, {description = "2 Minutes", data = "120"}, {description = "3 Minutes", data = "180"}, {description = "4 Minutes", data = "240"}, {description = "5 Minutes", data = "300"}, {description = "10 Minutes", data = "600"}, {description = "15 Minutes", data = "900"}, {description = "20 Minutes", data = "1200"}, {description = "25 Minutes", data = "1500"}, {description = "30 Minutes", data = "1800"}, }, default = "20", }, { name = "items", label = "Max held items", --You frikken need commas dude! options = { {description = "15 Items", data = 15}, {description = "16 Items", data = 16}, {description = "17 Items", data = 17}, {description = "18 Items", data = 18}, {description = "19 Items", data = 19}, {description = "20 Items", data = 20}, {description = "21 Items", data = 21}, --Like holy jesus christ please don't forget commas {description = "22 Items", data = 22}, {description = "23 Items", data = 23}, {description = "24 Items", data = 24}, {description = "25 Items", data = 25}, {description = "26 Items", data = 26}, {description = "27 Items", data = 27}, {description = "28 Items", data = 28}, -- Not actually sure if I need commas i havent tried it without {description = "29 Items", data = 29}, {description = "30 Items", data = 30}, }, default = "15", },} My modmain.lualocal function Digestionist(prefab) if not GLOBAL.TheWorld.ismastersim then return inst end -- Hunger timer prefab.components.digester.digesttime = GetModConfigData("timer") prefab.components.digester.task:Cancel() prefab.components.digester.task = prefab.components.digester.inst:DoPeriodicTask(prefab.components.digester.digesttime, function() prefab.components.digester:TryDigest() end) -- Inventory mod prefab.components.inventory.maxslots = GetModConfigData("items") prefab.components.inventory:GetNumSlots() print("Digest time is",prefab.components.digester.digesttime) print("Inventory slots are",prefab.components.inventory.maxslots) --]]endAddPrefabPostInit("lureplant", Digestionist) In my modinfo, I have the timer data set as a string, but it still works? But before I addedprefab.components.inventory:GetNumSlots()in the modmain.lua, it still gave me a comparing to string error even through I deleted the quotes from the items config data. I don't know why I thought this, unnecessary quotes deleted. Thanks to those who helped Edited March 20, 2015 by greatguys Link to comment https://forums.kleientertainment.com/forums/topic/52169-returns-are-throwing-me-off/#findComment-623293 Share on other sites More sharing options...
Maris Posted March 20, 2015 Share Posted March 20, 2015 It may work in some cases.x = "1"if x == 1 then --FALSE, because it's a string and can't be equal to number --...................endx = x + 1print(x) --Now it's 2, and it's a numberif x == 2 then --TRUE --.............end Link to comment https://forums.kleientertainment.com/forums/topic/52169-returns-are-throwing-me-off/#findComment-623300 Share on other sites More sharing options...
Maris Posted March 20, 2015 Share Posted March 20, 2015 Just learn lua! It takes about 15 minutes! http://tylerneylon.com/a/learn-lua/ Link to comment https://forums.kleientertainment.com/forums/topic/52169-returns-are-throwing-me-off/#findComment-623301 Share on other sites More sharing options...
greatguys Posted March 20, 2015 Author Share Posted March 20, 2015 I- oh... I uhh... Thanks. Link to comment https://forums.kleientertainment.com/forums/topic/52169-returns-are-throwing-me-off/#findComment-623312 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now