Jump to content


Dragon53535's Content

There have been 2 items by Dragon53535 (Search limited from 30-March 23)


By content type

See this member's

Sort by                Order  

#279543 How do I get a boolean to become false? I've tried everything and it does...

Posted by Dragon53535 on 26 November 2020 - 10:54 PM in Ask a Pro

That's mostly because of the way your code is set up. You actually don't have any while loops.
while not night do
    --Blah blah
    night = true
end
Changing night to true breaks out of the loop anyways. So you in essence don't have any loops at all.



#279539 How do I get a boolean to become false? I've tried everything and it does...

Posted by Dragon53535 on 20 November 2020 - 08:00 PM in Ask a Pro

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.