So I've done some testing and found that it is indeed the higher level of the program that is running, with the state information of the lower level.
I made a copy of the program (editor) to editor2. then ran editor with editor2 as a file to edit. Then inside the program I ran editor2 with a test file (print("hello")) and tried to exit. It exited as it was supposed to. However the top layer (editor) did not act as it was supposed to. It seems to have absorbed the file information from editor2 and the bRunning variable as well. But for some reason, even though bRunning is false, it's not exiting. Pressing the exit button does nothing.
I'm really at a loss. All the variables in question are local. I did a test to see if I could change local variables within their scope if a local variable was set to the same name:
local text = "1"
function layer2()
local text = "2"
print("layer2: " .. text)
end
print("function defined, not run")
print("layer1: " .. text)
layer2()
print("function run")
print("layer1: " .. text)
It printed 1, 2, 1 for the text variable, as it should have.
I'm at a loss here, I really have no idea what's going on. I have the feeling that it may be some weird bug in CC but I'm unsure.
EDIT: Now it appears that the first instances bRunning wasn't set to false as I said, it was set to "false". It was set to the string value of "false" which would explain why it wasn't exitting the program even though it was false. But this still doesn't explain why the string was passed back and put into the value of the boolean in the first instance. That wouldn't even be something I'd do in the program (passing a string to a boolean).EDIT 2: I tried the above code with booleans, testing if it was a string or not, and I moved the function to a separate file. The result was still the equivalent of 1, 2, 1. So it looks to be like something in my code, but I can't figure out what. I tried adding an os.sleep(3) at EOF to test if it was the F4 being carried over to the next pullEvent but that wasn't the case either. For anyone willing to take a look, this is the code I'm working with atm:
http://pastebin.com/2KDJfZijEDIT 3: I made a stupid mistake in testing. So the first level is actually getting boolean values from the second level. For example,
if bRunning == true or bRunning == false then
sDebugText = sDebugText .. " Running:" ..tostring(bRunning) end
will show in the debug that running is false (bool), but it wont exit the main loop, which is while bRunning do end. This is verified by this code which I just tested, that didn't solve the problem:
if bRunning == true then
bRunning = true
elseif bRunning == false then
bRunning = false
end
EDIT 4: I looked at all the locations of bRunning being used in the program, and they all deal with setting it as a bool or reading its value. The only one that doesn't is the debug string that does tostring(bRunning) so I tested that, but it wasn't the culprit either. I don't think this is something wrong with my program. I think it may be something wrong with CC/Lua…