Jump to content

Recommended Posts

Posted

ok, I doing tutorial and now I got an error "attempt to index field 'context'(a nil value)" in Start function

here is the code

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

end
function Script:PostRender(context)
for i = 1, self.itemSlots, 1 do

context:SetColor(1,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

 

please help smile.png

Posted

At the time of making these tutorials, you could retrieve the context from App. The standard main script has changed since then:

 

Replace

self.screenWidth = App.context:GetWidth()

 

You can also get the context like this:

self.screenWidth = Context:GetCurrent():GetWidth()

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.

×
×
  • Create New...