Jump to content

Error in inventory Script


tripper1977
 Share

Recommended Posts

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.

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

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

Link to comment
Share on other sites

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()

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...