ID:1564895
 
(See the best response by Sir Lazarus.)
Code:
change_door_state() //Close a door if it's open, open if it's closed
set src in view(1) //Must be within
if(density)
set name = "Open Door"
world << "You opened the door!"
density = 0
else
set name = "Close Door" //ERROR here
world << "You closed the door!"
density = 1


Problem description:

Hey guys. Got some downtime for my FINAL semester of college, and decided to check out BYOND again to see if it was still up and running, and after all these years, it was!

I decided to dive into the language, and now that I have 5 years of CS behind, I definitely understand the language a lot better than I did when I was 14, haha.

However, this is making me confused. I wanted a verb function that, depending on the door's density, would change names and do different things, like shutting and closing it. This gives me the error 26:error: =: conflicts with previous definition

Now, this totally could be because I just started an hour ago going through the DM Guide, but I don't understand why this doesn't work. It's not attempting to set the name to two different values at the same time. It's being set different when different conditions are met. While it'd be easy to just simply flip the density value with one function, I'd like to change the name and how it shows up in the menu to reflect this.

I'm sure this is an easy fix, but is there a way around this? Also, if anyone has an explanation on why something like this isn't allowed in BYOND, I'd love to hear it! Thanks guys!
Best response
Stuff like "set name" can only be done once, at the start of the definition of your verb.

You'll want to create two verbs and add/remove verbs from the src.verbs list.

/obj/door/New()
. = ..()

if (density)
src.verbs -= /obj/door/verb/close_door()
else
src.verbs -= /obj/door/verb/open_door()

/obj/door/verb/open_door() //Open a door if it's closed
set name = "Open Door"
set src in view(1) //Must be within

if (density)
world << "You opened the door!"

density = 0

src.verbs += new/obj/door/verb/close_door()
src.verbs -= /obj/door/verb/open_door()

/obj/door/verb/close_door() //Close a door if it's open
set name = "Close Door"
set src in view(1) //Must be within

if (!density)
world << "You closed the door!"

density = 1

src.verbs += new/obj/door/verb/open_door()
src.verbs -= /obj/door/verb/close_door()

Note: Untested code, but should be enough of an explanation.
Yup, got it, thanks for the quick help!