fluffyNest Posted October 24, 2015 Share Posted October 24, 2015 (edited) I'm doing something definitely in some horrible way. (UPD This problem is fixed. Second is coming)Code is not updated, its broken. First problem is[00:00:42]: [string "scripts/components/stackable.lua"]:62: attempt to compare table with numberLUA ERROR stack traceback: scripts/components/stackable.lua:62 in (method) OGet (Lua) <59-84> ../mods/<MineMod>/modmain.lua:30 in (method) Get (Lua) <26-63> scripts/components/inventory.lua:833 in () ? (Lua) <825-871> =(tail call):-1 in () (tail) <-1--1> scripts/components/inventory.lua:406 in (method) DropItem (Lua) <401-424> scripts/actions.lua:279 in (field) fn (Lua) <277-288> scripts/bufferedaction.lua:23 in (method) Do (Lua) <19-33> scripts/entityscript.lua:1199 in (method) PerformBufferedAction (Lua) <1191-1209> scripts/stategraphs/SGwilson.lua:2118 in (field) fn (Lua) <2117-2119> scripts/stategraph.lua:562 in (method) UpdateState (Lua) <530-574> scripts/stategraph.lua:601 in (method) Update (Lua) <593-621> scripts/stategraph.lua:123 in (method) Update (Lua) <107-146> scripts/update.lua:205 in () ? (Lua) <146-219>(Upd. Now im know that it's 'self' is nil)It's line if self.stacksize > num_to_get thenFile stackable.lua is original, not modified in fileSystem. I'm replacing two of its methods(Get,Put) with custom methods that doing some logic !and calling original methods(that stored in new vars: How to solve this? What am I doing wrong? modmain.lua (well it's part of it. Other code doesn't affects this part and stackable) local require = GLOBAL.requirelocal Stackable = require "components/stackable"--First custom method Getfunction NEGet( num ) local num_to_getNE = num or 1 --Calling original method local stc_get = Stackable:OGet( num ) <some custom code that manipulates its custom vars and also affects !finiteuses of the detached item> return stc_getend--Second custom method Putfunction NEPut( item, source_pos ) <logic that affects custom vars and reading item.finiteuses:GetUses()> local stc_put = Stackable:OPut( item, source_pos ) return stc_putend--temporal holders for original Get and Putlocal Stackable_Get_base = Stackable.Get or function(num) return nil endlocal Stackable_Put_base = Stackable.Put or function(item, source_pos) return nil end--more permament holdersStackable.OGet = Stackable_Get_baseStackable.OPut = Stackable_Put_base--replacing procedureStackable.Put = NEPutStackable.Get = NEGet--custom vars injectionStackable.NE_Durabilities = { 1}Stackable.NE_UseDurabilities = false Edited October 28, 2015 by fluffyNest Link to comment Share on other sites More sharing options...
DarkXero Posted October 25, 2015 Share Posted October 25, 2015 Are you sure you are not modifying self.stacksize with Stackable.NE_Durabilities at some point? Link to comment Share on other sites More sharing options...
fluffyNest Posted October 25, 2015 Author Share Posted October 25, 2015 (edited) DarkXero, yes, I'm sure. Thank you for the reply. This first problem is already solved. Aside from misspells and wrong logic in custom code there where wrong calling of original methods( because they where ho longer in stackable class?) and wrong declaration of new methods.It's should be:function NEGet( self, num )local stc_get = Stackable.OGet( self, num ) function NEPut( self, item, source_pos )local stc_put = Stackable.OPut( self, item, source_pos ) Edited November 2, 2015 by fluffyNest Link to comment Share on other sites More sharing options...
fluffyNest Posted October 25, 2015 Author Share Posted October 25, 2015 (edited) So, the second problem(kinda) has come. I'm write new var:bool to component stackable named 'somebool'modmain.lualocal require = GLOBAL.requirelocal Stackable = require "components/stackable"Stackable.somebool = falseIs there a way to make auto fire 'onchange' to another function?like here in 9 and 10 lines if this not something else(no auto-fire for stacksize&maxsize):data\scripts\coponents\stackable.lualocal Stackable = Class(function(self, inst) self.inst = inst self.stacksize = 1 -- Its a stack of one (ie the first item) self.maxsize = TUNING.STACK_SIZE_MEDITEMend,nil,{ stacksize = onstacksize, maxsize = onmaxsize,})Appreciate any help.___How to make spoilers in forum post? Edited October 25, 2015 by fluffyNest Link to comment Share on other sites More sharing options...
DarkXero Posted October 25, 2015 Share Posted October 25, 2015 (edited) You are right. For the record:Stackable.OPut( self, item, source_pos )equalsStackable:OPut( item, source_pos )The issue was with the NGet assigning num = self, and dropping the receiving num. That way, num was the table, self. Two ways here. 1)You make afunction Stackable:SetSomeBool(val) -- trigger onchange here self.somebool = valendand you use the method to set up the variable. 2)You use the global addsetter function from Class.lua.local function onsomeboolchange(self, somebool_value) print("Hello!", somebool_value)endlocal function stackablePostInit(self, inst) self.somebool = false GLOBAL.addsetter(self, "somebool", onsomeboolchange)endAddComponentPostInit("stackable", stackablePostInit)like this. <spoiler> stuff </spoiler> but with [] brackets[hello] stuff [/hello] How to make spoilers in forum post?[spoiler] stuff [/spoiler] Edited October 25, 2015 by DarkXero Link to comment Share on other sites More sharing options...
fluffyNest Posted October 26, 2015 Author Share Posted October 26, 2015 (edited) DarkXero, thanks. The funny thing I had read somewhere on forums that ".Fnc(self)==:Fnc()" but I'm forget that I have suppose to do the same with my own methods. 1) I'm gonna use this. Don't wanna kill the memory.2) Ah that a really nice function. Thank you for the new information. I'm just don't like that I don't know how its working. I mean does its consuming more resources than first option? stuff Get staff with spoilers. Except for this (for me It's looks like XML or something that I don't know).<div class="bbc_spoiler"> <span class="spoiler_title">Spoiler</span> <input type="button" class="bbc_spoiler_show" value="Show"> <div class="bbc_spoiler_wrapper"><div class="bbc_spoiler_content" style="display:none;"> stuff </div></div></div> Edited October 26, 2015 by fluffyNest Link to comment Share on other sites More sharing options...
fluffyNest Posted October 26, 2015 Author Share Posted October 26, 2015 (edited) So new "Function overriding" question appeared and it is about "._replica"s Is this possible to add new "net_" value to existing componentReplica? maybe like this: modmain.lualocal require = GLOBAL.requirelocal Stackable_replica = require "components/stackable_replica"Stackable_replica._NE_Durabilities = net_smallbytearray(Stackable_replica.inst.GUID, "stackable._NE_Durabilities")but its not working: attempt to index field 'inst' (a nil value) Edited October 26, 2015 by fluffyNest Link to comment Share on other sites More sharing options...
DarkXero Posted October 26, 2015 Share Posted October 26, 2015 1) I'm gonna use this. Don't wanna kill the memory. 2) Ah that a really nice function. Thank you for the new information. I'm just don't like that I don't know how its working. I mean does its consuming more resources than first option? Use whatever is more comfortable to you. but its not working: attempt to index field 'inst' (a nil value) That is not working because inst exists when the class is called by the game, passing the entity on construction.What you can access is Stackable_replica._ctor, as _ctor is a method assigned during the Class() function execution.local require = GLOBAL.requirelocal Stackable_replica = require "components/stackable_replica"local old_ctor = Stackable_replica._ctorStackable_replica._ctor = function(self, inst) old_ctor(self, inst) self._NE_Durabilities = GLOBAL.net_smallbytearray(inst.GUID, "stackable._NE_Durabilities")end Link to comment Share on other sites More sharing options...
fluffyNest Posted October 26, 2015 Author Share Posted October 26, 2015 (edited) Much appreciated. Lua confuse me so much that i forget everything that I have learned before.Probably need to just learn lua already... What is more comfortable to me. It's a little complicated. Because it's not about only me.And it's not so intuitive to have bool var that actually read-only but it's not read-onlyI'm so missing properties, eh... Just the last question can be this code transferred to other file?like this: modmain.lualocal require = GLOBAL.requirelocal somecode = require "somecode" --its will be "scripts\somecode.lua"?somecode:Execute()somecode.luafunction Somecode:Execute() local require = GLOBAL.require local Stackable_replica = require "components/stackable_replica" local old_ctor = Stackable_replica._ctor Stackable_replica._ctor = function(self, inst) old_ctor(self, inst) self._NE_Durabilities = GLOBAL.net_smallbytearray(inst.GUID, "stackable._NE_Durabilit ies") endend Edited October 26, 2015 by fluffyNest Link to comment Share on other sites More sharing options...
DarkXero Posted October 26, 2015 Share Posted October 26, 2015 Much appreciated. Lua confuse me so much that i forget everything that I have learned before. Probably need to just learn lua already... What is more comfortable to me. It's a little complicated. Because it's not about only me. And it's not so intuitive to have bool var that actually read-only but it's not read-only I'm so missing properties, eh... Lua is flexible, so you can make it look like python or like java or like whatever you want. Just the last question can be this code transferred to other file? With world.lua:print("This is world")globalvar = 123Doinglocal hello = require("world")equalslocal hello = function() print("This is world") globalvar = 123endthe first time you call it. Using require the next times will return you a reference (if there was a return in world.lua) or nothing, instead of running the file again and again. You can use modimport to load code from multiple files, in order to structure your code. You have in your mod folder:- modmain.lua- modinfo.lua- somecode.lua modmain.lua:modimport("somecode.lua")somecode.lua:local require = GLOBAL.requirelocal Stackable_replica = require "components/stackable_replica"local old_ctor = Stackable_replica._ctorStackable_replica._ctor = function(self, inst) old_ctor(self, inst) self._NE_Durabilities = GLOBAL.net_smallbytearray(inst.GUID, "stackable._NE_Durabilities")endmodimport loads the file you specify. Unlike require, modimport's root is where modmain is, instead of scripts.And the files you modimport get to use the mod environment (AddPrefabPostInit, AddComponentPostInit, etc.) Link to comment Share on other sites More sharing options...
fluffyNest Posted October 28, 2015 Author Share Posted October 28, 2015 Ah thank you very much. Link to comment 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