Possibly Uninitialized

I normally declare _H and _W as global in main.lua.

When I use the _H or _W on let’s say scene1.lua, there is this warning saying : “Possibly Uninitialized”

why and how to fix it?

Thank you [import]uid: 31508 topic_id: 32207 reply_id: 332207[/import]

Hi there,

Can you post the code showing how you are initializing the variables as global in main.lua? That would help debug your issue.

  • Andrew [import]uid: 109711 topic_id: 32207 reply_id: 128227[/import]

this is the code

-- main.lua  
local storyboard = require "storyboard";  
  
display.setStatusBar ( display.HiddenStatusBar )  
  
--Setting up Global variables  
\_W = display.contentWidth;  
\_H = display.contentHeight;  
  
-- Load first scene mainmenu.lua  
local options=   
{  
 effect = "fade",  
 time = 10000  
}  
storyboard.gotoScene( "mainmenu", options )  
-- mainmenu.lua  
local storyboard = require( "storyboard" )  
local scene = storyboard.newScene()  
  
function scene:createScene( event )  
 local menuGroup = self.view  
  
 mainBg = display.newImageRect("images/menubg.png", 820, 960);  
 mainBg.x = \_W/2;  
 mainBg.y = \_H/2;  

the last 2 lines of mainmenu.lua show the warning “Possibly Uninitialized” (warning sign in yellow color triangle next to code numbering) [import]uid: 31508 topic_id: 32207 reply_id: 128229[/import]

Hi there,

Your code looks fine to me. I had at first thought the warning you referred to was an output to the terminal when you ran your code, but now I realize that you’re using some sort of code editor or IDE, like Glider, and it’s in the editor that you’re seeing the warning, right? In that case, it’s an issue with the editor not realizing that the variable was initialized. If the warning bothers you, I imagine there’s some way to address it or suppress it, but I’m not familiar with any of the common editors, so I wouldn’t be able to tell you exactly how.

  • Andrew [import]uid: 109711 topic_id: 32207 reply_id: 128233[/import]

@Andrew thank you,
yes the warning is in the IDE. [import]uid: 31508 topic_id: 32207 reply_id: 128234[/import]

@Andrew,
Thanks for your help.

@bpran,
We are in the process of rewriting the parser so that it handles multiple files/projects better. This is the exact kind of false warning we are working on eliminating. We will be sure to check this code snippet during testing.

You can suppress warnings via options->Glider->Editor->Warnings

Regards,
M.Y. Developers
[import]uid: 55057 topic_id: 32207 reply_id: 128342[/import]

I am using mac version, I don’t see Warnings under Editor [import]uid: 31508 topic_id: 32207 reply_id: 128345[/import]

I think I found it,
it’s under Preference > Glider’s Option > Editor > Warnings Enable/Disable [import]uid: 31508 topic_id: 32207 reply_id: 128346[/import]

Hi there,

Can you post the code showing how you are initializing the variables as global in main.lua? That would help debug your issue.

  • Andrew [import]uid: 109711 topic_id: 32207 reply_id: 128227[/import]

this is the code

-- main.lua  
local storyboard = require "storyboard";  
  
display.setStatusBar ( display.HiddenStatusBar )  
  
--Setting up Global variables  
\_W = display.contentWidth;  
\_H = display.contentHeight;  
  
-- Load first scene mainmenu.lua  
local options=   
{  
 effect = "fade",  
 time = 10000  
}  
storyboard.gotoScene( "mainmenu", options )  
-- mainmenu.lua  
local storyboard = require( "storyboard" )  
local scene = storyboard.newScene()  
  
function scene:createScene( event )  
 local menuGroup = self.view  
  
 mainBg = display.newImageRect("images/menubg.png", 820, 960);  
 mainBg.x = \_W/2;  
 mainBg.y = \_H/2;  

the last 2 lines of mainmenu.lua show the warning “Possibly Uninitialized” (warning sign in yellow color triangle next to code numbering) [import]uid: 31508 topic_id: 32207 reply_id: 128229[/import]

Hi there,

Your code looks fine to me. I had at first thought the warning you referred to was an output to the terminal when you ran your code, but now I realize that you’re using some sort of code editor or IDE, like Glider, and it’s in the editor that you’re seeing the warning, right? In that case, it’s an issue with the editor not realizing that the variable was initialized. If the warning bothers you, I imagine there’s some way to address it or suppress it, but I’m not familiar with any of the common editors, so I wouldn’t be able to tell you exactly how.

  • Andrew [import]uid: 109711 topic_id: 32207 reply_id: 128233[/import]

@Andrew thank you,
yes the warning is in the IDE. [import]uid: 31508 topic_id: 32207 reply_id: 128234[/import]

@Andrew,
Thanks for your help.

@bpran,
We are in the process of rewriting the parser so that it handles multiple files/projects better. This is the exact kind of false warning we are working on eliminating. We will be sure to check this code snippet during testing.

You can suppress warnings via options->Glider->Editor->Warnings

Regards,
M.Y. Developers
[import]uid: 55057 topic_id: 32207 reply_id: 128342[/import]

I am using mac version, I don’t see Warnings under Editor [import]uid: 31508 topic_id: 32207 reply_id: 128345[/import]

I think I found it,
it’s under Preference > Glider’s Option > Editor > Warnings Enable/Disable [import]uid: 31508 topic_id: 32207 reply_id: 128346[/import]