I use the following method and it always works without errors:
To show it I use:
inventory_main.flags = SHOW;
To hide it I use:
inventory_main.flags &= ~SHOW;
That's somewhat flawed
inventory_main.flags = SHOW; will reset all other flags set, you need to use inventory_main.flags |= SHOW; to set just this flag
if you're struggling with this you'd be better using the macros predefined set() and reset()
also look at toggle(), this will save checking if it's shown in the first place