Jump to content




Exits program (without an error) [solved]


  • You cannot reply to this topic
6 replies to this topic

#1 Blue

  • Members
  • 309 posts
  • LocationGlass/UX/main.lua

Posted 11 May 2014 - 06:57 AM

http://pastebin.com/gQqHpW5m

It exits the program(at line 78 and 97) and returns to the shell.I'm guessing it's a problem with the variables.
It does not error it just stops because of the if statements.

Edited by Glass Systems, 12 May 2014 - 03:10 PM.


#2 CometWolf

  • Members
  • 1,283 posts

Posted 11 May 2014 - 10:15 AM

Atleast tell us where it exits...

#3 Blue

  • Members
  • 309 posts
  • LocationGlass/UX/main.lua

Posted 11 May 2014 - 02:43 PM

View PostCometWolf, on 11 May 2014 - 10:15 AM, said:

Atleast tell us where it exits...
It exits near the if statements.Sorry about that (line 78 and 97).

Edited by Glass Systems, 11 May 2014 - 02:45 PM.


#4 Blue

  • Members
  • 309 posts
  • LocationGlass/UX/main.lua

Posted 12 May 2014 - 04:53 AM

I tried turning the local variables into global variables and it worked.Do i have to have global variables?

#5 CometWolf

  • Members
  • 1,283 posts

Posted 12 May 2014 - 06:32 AM

Provided the variable is defined in another script and you use shell.run to execute this one, then yes you do.

#6 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 12 May 2014 - 01:50 PM

Learn how to use locals properly and also learn to use elseif/else
local select -- Make this local here instead so you can use it later
while true do
	local event, button, X, Y = os.pullEvent("mouse_click")
	local XY = X..","..Y
	if XY=="1,8" then
		select="add" -- You can't localize this here if you want to use it elsewhere, because then it will be local to this 'if' statement only
		break

	elseif XY=="1,9" then -- Use elseif instead
		select="remove" -- Same here, if you localize it here you can only use it in this 'if' statement
		break
	end
end

Looking on how you use locals I'll give a short explanation with some code
while true do
	local foo = "bar"
	break
end
print( foo ) -- foo = nil since it was localized in the 'while' loop
local foo = true
if foo then
	local bar = "Hello World!"
end
print( bar ) -- bar = nil since it was localized in the 'if' statement

Edited by TheOddByte, 12 May 2014 - 01:50 PM.


#7 Blue

  • Members
  • 309 posts
  • LocationGlass/UX/main.lua

Posted 12 May 2014 - 03:09 PM

View PostTheOddByte, on 12 May 2014 - 01:50 PM, said:

Learn how to use locals properly and also learn to use elseif/else
local select -- Make this local here instead so you can use it later
while true do
	local event, button, X, Y = os.pullEvent("mouse_click")
	local XY = X..","..Y
	if XY=="1,8" then
		select="add" -- You can't localize this here if you want to use it elsewhere, because then it will be local to this 'if' statement only
		break

	elseif XY=="1,9" then -- Use elseif instead
		select="remove" -- Same here, if you localize it here you can only use it in this 'if' statement
		break
	end
end

Looking on how you use locals I'll give a short explanation with some code
while true do
	local foo = "bar"
	break
end
print( foo ) -- foo = nil since it was localized in the 'while' loop
local foo = true
if foo then
	local bar = "Hello World!"
end
print( bar ) -- bar = nil since it was localized in the 'if' statement
Thanks :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users