Jump to content


Dragon53535

Member Since 15 Feb 2012
Offline Last Active Nov 20 2020 08:02 PM
*****

Posts I've Made

In Topic: How do I get a boolean to become false? I've tried everything and it does...

20 November 2020 - 08:00 PM

Lupus you're getting rusty...

local night = false
local nightmode = false
while not night do
	rs.setOutput("right", true)
	rs.setOutput("back", false)
	sleep(15)
	rs.setOutput("right", false)
	rs.setOutput("back", false)
	sleep(3)
	rs.setOutput("right", false)
	rs.setOutput("back", true)
	sleep(15)
	rs.setOutput("right", false)
	rs.setOutput("back", false)
	rs.setOutput("left", false)
	sleep(3)
	if rs.getInput("front") then
		break
	end
	local night = true -- ISSUE
	local nightmode = true --ISSUE
end
while not nightmode do
	rs.setOutput("right", false)
	rs.setOutput("back", false)
	sleep(1)
	rs.setOutput("left", true)
	if rs.getInput("front") == false then
		break
	end
	local nightmode = not nightmode --ISSUE
	local night = not night --ISSUE
end

All of the lines marked as ISSUE are creating new variables inside the loops. They are not modifying the earlier variables as you used the local keyword. Remove the local keyword and you're in business.

Remember, use local only when you're creating the variable to start with. If you use it afterwards, the code just makes a new variable and hides the earlier one.