Alienhead Posted April 15 Share Posted April 15 I wasn't for sure if this was a bug or if it is by design so I figured I'd ask here: Creating anything inside a Require() file or a component with the keyword Local results in the creation not showing. Be it a mesh, sprite, model or whatever.. Example: This is inside a Component script file. -- label if self.ynCreateDebugLabels then local sp = CreateSprite(world, self.font, "This is a sprite !", 14, TEXT_CENTER) sp:SetPosition(self.UAGCSliders[t]:GetPosition()) end It never shows up in the world. But it does exist as the SetPosition command never throws an error. This does: work as one would expect but only after declaring it as a Global. -- label if self.ynCreateDebugLabels then sp = CreateSprite(world, self.font, "This is a sprite !", 14, TEXT_CENTER) sp:SetPosition(self.UAGCSliders[t]:GetPosition()) end Quote I'm only happy when I'm coding, I'm only coding when I'm happy. Link to comment Share on other sites More sharing options...
Josh Posted April 15 Share Posted April 15 Makes sense to me. The local variable goes out of scope when the function finishes, and the variable is collected and the value deleted. In Ultra, we can actually make use the Lua's garbage collection Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Alienhead Posted April 15 Author Share Posted April 15 I see, I see... good to know. Quote I'm only happy when I'm coding, I'm only coding when I'm happy. Link to comment Share on other sites More sharing options...
Alienhead Posted April 15 Author Share Posted April 15 One last LUA question, and this one puzzles me. I have a file Require() I use for general utility stuff.. Inside the file is a bunch of functions. I can add a sprite to the table like so.. it prints the name fine. function AddSpriteLabelToTable(sprite) if splabel == nil then splabel = {} end table.insert ( splabel, { sprite = sprite, }) for t, s in ipairs ( splabel ) do consolepad:addtext(s.sprite,name) end end When calling an update function that access this global table I get all kinds of trouble. Usually always resulting in nil or missing table. function UpdateSpriteLabels() for t, s in pairs ( splabel ) do consolepad:addtext(s.sprite,name) end end These functions are located in the same Require() file, but oddly trying to access the table created in the AddSpriteLabelToTable function results in error. Do all my tables need to be created on the top level in order for the entire project to access them? be it Require() files or component scripts? LE allowed this kinda of access, I was just wondering if this is something new and if so where do I need to define global tables that all scripts can access? Quote I'm only happy when I'm coding, I'm only coding when I'm happy. Link to comment Share on other sites More sharing options...
Josh Posted April 15 Share Posted April 15 I am not sure. Do you know how to set breakpoints in VSCode? That might allow you to view the global vars. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Alienhead Posted April 15 Author Share Posted April 15 yes I will attempt to find where it breaks.. But I can tell you now the function does not recognize the table at all. This holds true when creating a table in a component script as well.. self.atable = {} table.insert( self.atable, { somevalue = 10 } then in a different function of the same script file the table is not recognized Quote I'm only happy when I'm coding, I'm only coding when I'm happy. Link to comment Share on other sites More sharing options...
Alienhead Posted April 15 Author Share Posted April 15 This works: splabel = {} function AddSpriteLabelToTable(sprite) table.insert ( splabel, { sprite = sprite, }) end function UpdateSpriteLabels() for t, s in pairs ( splabel ) do consolepad:addtext(s.sprite,name) end end This does not: function AddSpriteLabelToTable(sprite) if splabel == nil then splabel = {} end table.insert ( splabel, { sprite = sprite, }) end function UpdateSpriteLabels() for t, s in pairs ( splabel ) do ---- CRASH NO SUCH TABLE consolepad:addtext(s.sprite,name) end end Quote I'm only happy when I'm coding, I'm only coding when I'm happy. 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.