71 posts
Location
Tampa Bay, Florida
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?
7508 posts
Location
Australia
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?
62 posts
Location
Australia
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.
7508 posts
Location
Australia
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.
8543 posts
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.
7508 posts
Location
Australia
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.
8543 posts
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.
7508 posts
Location
Australia
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.