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

Show Current Status help

Started by SNWLeader, 14 December 2012 - 01:19 AM
SNWLeader #1
Posted 14 December 2012 - 02:19 AM
I am trying to make a Command Center that in the Main Page that it tells me that the door is already OPEN or CLOSED.
I was going to set a variable everytime the door is toggled, but I do not know how to get the message to display.
Could someone tell me how to get the variable to print what it states?
theoriginalbit #2
Posted 14 December 2012 - 02:29 AM
Please give some more info. Is it a boolean variable? or are you storing it as a string? or a number?
JoshhT #3
Posted 14 December 2012 - 04:18 AM
Lol…

print(v)

v being the variable. Will print exactly what the variable states.
Whether it be a boolean value, an integer, or a string.
theoriginalbit #4
Posted 14 December 2012 - 04:37 AM
Lol…

print(v)

v being the variable. Will print exactly what the variable states.
Whether it be a boolean value, an integer, or a string.

Actually if they are printing a string concatenation with a boolean like so print("This statement is "..false) then that would actually return an error!
You need to do print("This statement is "..tostring(false)) when trying to print boolean values with strings.
Hence checking first, I like to help, not blindly answer hoping to answer correctly.
Lyqyd #5
Posted 14 December 2012 - 04:47 AM
You are correct. However, when print()ing a single variable (no concatenation, etc.), at least in ComputerCraft, it will automatically be tostring()'d.
theoriginalbit #6
Posted 14 December 2012 - 04:53 AM
You are correct. However, when print()ing a single variable (no concatenation, etc.), at least in ComputerCraft, it will automatically be tostring()'d.

While you are also correct, i was not making any assumptions about how they actually wanted it to print. Based of what they were saying it could have been part of a far more elaborate GUI and required some concatenation.
Lyqyd #7
Posted 14 December 2012 - 04:57 AM
Well, the original post points us toward wanting to use a Boolean:


isDoorOpen = false
print(isDoorOpen and "OPEN" or "CLOSED")

OP, see if that does basically what you want. Just set isDoorOpen to true or false (no quotes!) when you open or close the door.
theoriginalbit #8
Posted 14 December 2012 - 05:03 AM
Well, the original post points us toward wanting to use a Boolean:


isDoorOpen = false
print(isDoorOpen and "OPEN" or "CLOSED")

OP, see if that does basically what you want. Just set isDoorOpen to true or false (no quotes!) when you open or close the door.

Ahh yes, lua's strange interpretation of the Ternary Operator.