ID:1281409
 
(See the best response by Kaiochao.)
Code:
mob/verb
intangible()
density = 0
if(density = 0)
density = 1


Problem description:I am really new to coding. I haven't coded anything original, haven't finished the DM Guide (I'm currently at chapter 6) and I believe I just don't grasp this. With my current understanding I think I should be able to make a verb that toggles a num value via if statements (maybe I just don't understand if statements) but I have not come to any conclusions on to how to do this. I've attempted a few things, all have been errors or things that cleared, but resulted in nothing happening.

I'm currently trying to make the intangible() verb a toggle, where if clicked while density is 0 it will restore density to 1 and if density is 0 it will make 0
it should be more like:

mob/verb
intangible()
if(!usr.density)
usr.density=1
else
usr.density=null
mob/verb
Intangible()
if(!density) density = 1
else if(density) density = 0
Best response
mob
verb/Verb_Name()
if(condition)
do this (if [condition] is true)
else
do this (if [condition] is false)


Example:
mob
verb/Intangible()
if(density) // density is true (1)
density = 0 // set density to false (0)
src << "You've become intangible!"

else // otherwise
density = 1 // set density to true (1)
src << "You're no longer intangible..."
Thank you all, this was very helpful.
In response to Eternal_Memories
Would
 density = !density
not work better? Since you're already reading !density in your example, and writing to the density var, should come out smoother.