tripper1977 Posted December 6, 2015 Share Posted December 6, 2015 hello all i have been following Jorn Theunissen inventory script on youtube and keep geting this error attempt to index field 'context' (a nil value) can any one help please thank you Quote Link to comment Share on other sites More sharing options...
macklebee Posted December 7, 2015 Share Posted December 7, 2015 You are going to have to give more information than that. Please post the script in question that is causing the error. While Jorn's videos are probably top notch, please be advised these are 3rd party scripts/video tutorials that are not officially supported by Leadwerks. So if you are having problems, its best to post the code along with the description of the problem. In any case, anytime you see the error 'index field 'xxxxxx' (a nil value)', it typically means that 'xxxxxx' has not been defined prior to you trying to use any of its associated class methods/functions. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
tripper1977 Posted December 8, 2015 Author Share Posted December 8, 2015 here you are i get the error from this bit self.screenWidth = App.context:GetWidth() Script.itemSlots = 4 --int "Item slots" Script.itemSize = Vec2(64,64) --Vec2 "Item size" Script.offset = 8.0 --float "Offset" Script.items = {} Script.screenWidth = 0 function Script:Start() self.screenWidth = App.context:GetWidth() item1 = InventoryItem:Create() item1.name = "Item B" System:Print(item1:GetItemInfo()) end function Script:PostRender(context) for i = 1, self.itemSlots, 1 do context:SetColor(1,1,1) local x = self.screenWidth - self.itemSize.x local y = (i * self.itemSize.y) + (i * self.offset) context:DrawRect(x,y, self.itemSize.x, self.itemSize.y) end end Quote Link to comment Share on other sites More sharing options...
macklebee Posted December 8, 2015 Share Posted December 8, 2015 The earlier versions of LE3 used App.lua which included the App class with the App:Start() and App:Loop(). That was later removed as a requirement and now the main lua script is just Main.lua without the App class. My guess is that you are using the Main.lua script as your main script, so that means the App.context does not exist. I would change this line: self.screenWidth = App.context:GetWidth() to these two lines: local context = Context:GetCurrent() self.screenWidth = context:GetWidth() or to this combined one-liner: self.screenWidth = Context:GetCurrent():GetWidth() Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
tripper1977 Posted December 8, 2015 Author Share Posted December 8, 2015 yes this one works perfect thank you for your help self.screenWidth = Context:GetCurrent():GetWidth() Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.