ID:262775
 
Code:
mob
verb
Hud_Display()
set category = "Settings"
set name = "Change Hud Display"
var/on = 0
if(on == 0)
src.client.screen += new/obj/Screen
on=1
else
src.client.screen -= new/obj/Screen
on=0


Problem description:
Ok here is what the problem is, when i click on Chnage Hud Displayit the screen appers, but when i click on it again the screen doesn't disappear.

Why is that?

If you try and look at what the compiler will see that as, you will realise that you're trying to remove something you just created. Also, you're storing your "on" variable inside of the verb. That is just a temporary variable, which will have no effect if you use the verb twice. To solve this, you have to hold the boolean variable as a mob var. To actually remove the hud, you can delete them or make them invisible.

This is what this might look like:
mob
var
hud_on // is the hud on or not?
verb
hud_display()
set category = "Settings"
set name = "Change Hud Display"
hud_on = !hud_on // toggle through hud_on from 1 and 0
if(hud_on)
draw_hud()
else
for(var/obj/Screen/s in client.screen)
del(s) // delete all instances of hud objects in client.screen

draw_hud()
client.screen += new /obj/Screen
// and other hud objects


~~> Unknown Person
Wait - what? Seriously, is that a sentance? Take the time to clearly communicate what you're trying to say. If the only obj on the screen is a /obj/screen and you tell it to get rid of it by subtracting, then of course it's going to get rid of it. Now, what I think what you're trying to say, is that you click it twice and it does what it's supposed to, but on the third time you run into a dilemma. Correct? So, the problem is thus: #1) the variable is local and not global, therefore everytime the variable is initiated via access of the verb (the same applies in procs) it will not save but be created anew, and #2) though it really isn't the cause of your problem, change src to usr because, usr is for verbs and src is for procs.
Sayian Hunter wrote:

>           var/on = 0
> if(on == 0)
> src.client.screen += new/obj/Screen
> on=1
> else


The problem is right there. You set the variable 'on' to 0, then test if its 0 and you expect it to ever not be 0? Even if the variable wasn't local (which it is, you need to set a variable on the mob itself, not just create a local variable in the proc) you are resetting it to 0 before doing the if statement!