This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Cheska's profile picture

Question: Basic Question about boolean values and help with code

Started by Cheska, 28 February 2013 - 04:00 AM
Cheska #1
Posted 28 February 2013 - 05:00 AM
Hey guys!

I'm a total newbie to programming and got a basic question about true and false: how does the computer save them to the next line? I mean, if I got a statement that results in either false or true (redstone.Input e.g.), do I have to conserve it somehow to further work with it?

Here is my code and unfortunately it doesn't work.

redstone.testBundledInput("back", colors.white)
if true then
for i=1, 4 do
redstone.setBundledOutput("back", colors.orange)
sleep(0.5)
redstone.setBundledOutput("back", 0)
sleep(0.5)
else
redstone.setBundledOutput("back", colors.orange)
sleep(0.5)
redstone.setBundledOutput("back", 0)

Maybe somebody can help me?
Lyqyd #2
Posted 28 February 2013 - 08:53 AM
Split into new topic.

Why not just use the boolean value directly?

if rs.testBundledInput("back", colors.white) then
JokerRH #3
Posted 28 February 2013 - 10:14 AM
An if statement always requires a boolean type, therefor a true statement.
True statements are for example
1==1
2 < 3

or of course a simple true.
(You can probably imagine that 0==1 is false)

In your case the function you call will either return true or false.
That means you can either write the function call in the if statement directly or you allocate your yield to a variable

b = func()
If b==true then ...

--or(as it already is a boolean variable)

if b then ...

Your if true then will obviously always be true…
ChunLing #4
Posted 28 February 2013 - 12:53 PM
Note that all conditionals can take any value, and will treat all values other than nil or false as being true.