Watch for a variable change?

I’m a relative noob to debugging but have been able to use breakpoints and the step through commands quite well in Glider. Thanks for a nice tool!

I’m trying to track down a problem where I “loose” a variable that I pass to a function prior to it being passed. So I’m trying to figure out at what point it is removed so I can figure out why that is.

Is there a way to set a flag to watch for a state change or removal of a variable? Is this what the “watches” window is for?

I’ve been trying to bracket it with some breakpoints and then either step through or step back but that hasn’t been working as well as I would have hoped.

Thanks for any help you can offer! :slight_smile:

[import]uid: 105707 topic_id: 32081 reply_id: 332081[/import]

Hello Eho,

Yes you would use watches for this purpose but it is not possible to do because the “loadstring” is disabled. see the post:
http://developer.coronalabs.com/content/changes-lua

Unfortunately this seems to be Apple’s policy. Without the loadstring function, evaluating an expression like
“var == null”
is not possible. Sorry there is no other way around this.

One caveat to watch out for though. Just what do you mean by “loose” a variable? Does it become nil? Be aware that not all locals show up in the stack if they are not used within the function.

local x = 1  
function func1()  
--x will not show up here even though it appears to be "in scope"  
end  
local x = 1  
function func1()  
--x will show up here because it is being used  
print(x)  
end  

Thats just the way Lua works, it optimizes memory consumption this way.

Regards,
M.Y. Developers
[import]uid: 55057 topic_id: 32081 reply_id: 127860[/import]

OK, wow… I just spent 10 minutes condensing my code to share the key elements of my dilemma as a code sample and realized that my problem related to a simple capitalization error for my “mystery” variable (“sceneCells” had become “SceneCells”). Not only did this break my forward reference but your example above explains why I couldn’t find the original variable any longer in my Variable window.

I seem to really only use the Variable window at this point with my debugging. Based on what you mention above is there any way to use the watch window at all or is it superfluous at this point? I’m not clear on “watches”. Is there documentation I could look at?

Also, I’d like to better understand the call stack. Is this simply functions that are active? You can click on functions to move to them? Again, is there some documentation I should review?

Thanks you for your insight. I feel like a “real” programmer using Glider :slight_smile: [import]uid: 105707 topic_id: 32081 reply_id: 128010[/import]

Hello Eho,

Yes you would use watches for this purpose but it is not possible to do because the “loadstring” is disabled. see the post:
http://developer.coronalabs.com/content/changes-lua

Unfortunately this seems to be Apple’s policy. Without the loadstring function, evaluating an expression like
“var == null”
is not possible. Sorry there is no other way around this.

One caveat to watch out for though. Just what do you mean by “loose” a variable? Does it become nil? Be aware that not all locals show up in the stack if they are not used within the function.

local x = 1  
function func1()  
--x will not show up here even though it appears to be "in scope"  
end  
local x = 1  
function func1()  
--x will show up here because it is being used  
print(x)  
end  

Thats just the way Lua works, it optimizes memory consumption this way.

Regards,
M.Y. Developers
[import]uid: 55057 topic_id: 32081 reply_id: 127860[/import]

Hello Eho,

Watches are currently not functional. Sorry. You can achieve similar results by checking a box next to the variable and right clicking for filter view.

" I’d like to better understand the call stack."
Sure. Say you have a utility function

local function add(a,b)  
return a+b  
end  

and you have multiple functions calling it

local function wrong()  
add(1,nil)  
end  
  
local function right()  
add(1,2)  
end  

It might be difficult to determine where the error came from but if you look in the call stack you can easily see that the error came from the wrong() function. So you can think of it as a history of your code.

Regards,
M.Y. Developers

[import]uid: 55057 topic_id: 32081 reply_id: 128014[/import]

I appreciate the insight. No problem about watches, just good to know their current state.

I will take a look at the variable filter view.

Thanks for the example regarding the call stack. [import]uid: 105707 topic_id: 32081 reply_id: 128021[/import]

OK, wow… I just spent 10 minutes condensing my code to share the key elements of my dilemma as a code sample and realized that my problem related to a simple capitalization error for my “mystery” variable (“sceneCells” had become “SceneCells”). Not only did this break my forward reference but your example above explains why I couldn’t find the original variable any longer in my Variable window.

I seem to really only use the Variable window at this point with my debugging. Based on what you mention above is there any way to use the watch window at all or is it superfluous at this point? I’m not clear on “watches”. Is there documentation I could look at?

Also, I’d like to better understand the call stack. Is this simply functions that are active? You can click on functions to move to them? Again, is there some documentation I should review?

Thanks you for your insight. I feel like a “real” programmer using Glider :slight_smile: [import]uid: 105707 topic_id: 32081 reply_id: 128010[/import]

Hello Eho,

Watches are currently not functional. Sorry. You can achieve similar results by checking a box next to the variable and right clicking for filter view.

" I’d like to better understand the call stack."
Sure. Say you have a utility function

local function add(a,b)  
return a+b  
end  

and you have multiple functions calling it

local function wrong()  
add(1,nil)  
end  
  
local function right()  
add(1,2)  
end  

It might be difficult to determine where the error came from but if you look in the call stack you can easily see that the error came from the wrong() function. So you can think of it as a history of your code.

Regards,
M.Y. Developers

[import]uid: 55057 topic_id: 32081 reply_id: 128014[/import]

I appreciate the insight. No problem about watches, just good to know their current state.

I will take a look at the variable filter view.

Thanks for the example regarding the call stack. [import]uid: 105707 topic_id: 32081 reply_id: 128021[/import]