string value is nil even after if-else statement

Started by TheTinyDeskEngineer, Dec 28, 2021, 02:37 PM

Previous topic - Next topic

TheTinyDeskEngineer

I'm working on a program using the Advanced Peripherals mod to make a computer lower a hidden elevator when I send a specific hidden message. However, it seems I can't concatenate a string and a boolean, and I can't use .toString() either. so I set up an if-else statement to create a string value based on what the bool is, and now sending a regular chat message displays correctly, but when I send a hidden one it says the string value is nil. I did some more testing by putting print calls in both the if and else statement, both run as expected, and I don't understand why it isn't working.

Here's the relevant code:
local event, username, message, uuid, isHidden = os.pullEvent("chat")
local stringHidden = nil
if isHidden then
    print("isHidden = true")
    stringHidden = "yes"
else
    print("isHidden = false")
    stringHidden = "no"
end
print("user: " .. username .. " message: " .. message .. " hidden: .. stringHidden)

I always get the error on the last print call.

TheTinyDeskEngineer

nevermind I just misspelled the name of the stringHidden variable in the if statement

TheTinyDeskEngineer

...And now the problem is a while loop that's used for checking if the sender is in a whitelist.

Have I forgotten where tables start in Lua again?

QuickMuffin8782

Quote from: TheTinyDeskEngineer on Dec 28, 2021, 02:55 PM...And now the problem is a while loop that's used for checking if the sender is in a whitelist.

Have I forgotten where tables start in Lua again?
You might as of have. You can learn more on tables on the official Lua website for Lua 5.1, since ComputerCraft operates under that version.
GOTTA GO FAST!!!! - Sunrise Studios now calling testers! Check the post!
Gitlab - Join my official discord! - SS Discord