ID:787125
 
(See the best response by Albro1.)
Code:
obj
Cannon2
name = "CannonWep"
icon = 'bars.dmi'
screen_loc = "4,1"
icon_state = "can"
layer = MOB_LAYER+100
Click()
if(usr.Level<10)
usr<<"Not Powerful Enough"
return
if(usr.DyingWill <= 50)
usr<<"You dont have enough DyingWill!"
return
if(usr.firing)
usr<<"Not now."
return
if(usr.froze)
usr<<"Your frozen"
return
if(usr.resting)
usr<<"Not while resting"
return
if(usr.meditating)
usr<<"Not while meditating"
return
if(usr.Frozen)
usr<<"Your frozen"
return
if(usr.captured)
usr<<"Your captured"
return
if(!usr.firing)
view()<<"<font color = red>[usr]: I will Defeat You with my Flame Weapon!"
usr<<'DyingWill.wma'
if(usr.skygg==1&&!usr.DWarmor)
usr.overlays += 'SkyCan.dmi'
usr.DWP = usr.DWP*1.1
usr.attack = usr.attack*1.1
usr.defence = usr.defence*1.1
usr.DWarmor =1
if(usr.FOR)
usr.attack=usr.attack*2
if(usr.HI)
usr.DWP=usr.DWP*3
return
if(usr.stgg==1&&!usr.DWarmor)
usr.overlays += 'StormCan.dmi'
usr.DWP = usr.DWP*1.05
usr.attack = usr.attack*1.05
usr.defence = usr.defence*1.05
usr.DWarmor =1
return
if(usr.sugg==1&&!usr.DWarmor)
usr.overlays += 'SunCan.dmi'
usr.DWP = usr.DWP*1.05
usr.attack = usr.attack*1.05
usr.defence = usr.defence*1.05
usr.DWarmor =1
return
if(usr.mgg==1&&!usr.DWarmor)
usr.overlays += 'MistCan.dmi'
usr.DWP = usr.DWP*1.05
usr.attack = usr.attack*1.05
usr.defence = usr.defence*1.05
usr.DWarmor =1
return
if(usr.rgg==1&&!usr.DWarmor)
usr.overlays += 'RainCan.dmi'
usr.DWP = usr.DWP*1.05
usr.attack = usr.attack*1.05
usr.defence = usr.defence*1.05
usr.DWarmor =1
return
if(usr.cgg==1&&!usr.DWarmor)
usr.overlays += 'CloudCan.dmi'
usr.DWP = usr.DWP*1.05
usr.attack = usr.attack*1.05
usr.defence = usr.defence*1.05
usr.DWarmor =1
return
if(usr.tgg==1&&!usr.DWarmor)
usr.overlays += 'ThunderCan.dmi'
usr.DWP = usr.DWP*1.05
usr.attack = usr.attack*1.05
usr.defence = usr.defence*1.05
usr.DWarmor =1
return


Problem description:

My Goal Is Simple, I Just Want to make a clickable button with this obj so where the player Click Once, It On, Activate. Click Again Its Off Remove Overlay.

I tried many things like.

            else if(usr.DWarmor)
usr.overlays -= 'example.dmi'


but it never works..? Someone help me out.

What Am i doing wrong. Thanks in an Advance, For bringing me this far.

Edit: My Problem Is That The Overlay Never Goes Off once activated.

Even Trying many coding.
Best response
You have to set a flag.

mob/var/has_overlay = FALSE

mob/proc/toggle_overlay()
if(has_overlay) // You don't have to do == here. This automatically checks if it is set to a positive value, or TRUE(Which compiles as 1, unlike FALSE which compiles as 0)
overlays -= 'example.dmi'
else
overlays += 'example.dmi'


Try to keep your code a little cleaner. Instead of having that giant wall of text in Click(), call a proc. Split your code up to make it more manageable.
well that code wasn't what i was looking 4 but I need it to be in a Click() Since its a Skills Bar.


Basically I want to know Why,This Work.

 obj
DW
name = "DyingWill"
icon = 'bars.dmi'
screen_loc = "3,1"
icon_state = "flame"
layer = MOB_LAYER+100
Click()
if(usr.Level<100)
usr<<"Not Powerful Enough"
return
if(usr.DyingWill <= 50)
usr<<"You dont have enough DyingWill!"
return
if(usr.firing)
usr<<"Not now."
return
if(usr.froze)
usr<<"Your frozen"
return
if(usr.resting)
usr<<"Not while resting"
return
if(usr.meditating)
usr<<"Not while meditating"
return
if(usr.Frozen)
usr<<"Your frozen"
return
if(usr.captured)
usr<<"Your captured"
return
if(!usr.DWarmor&&!usr.firing)
view()<<"<font color = red>[usr]: I will Defeat You with my DYING WILL FlAME!"
usr<<'DyingWill.wma'
if(usr.Acro&&usr.Level>=100)
goto Acro
if(usr.Level>=200)
goto bigflame
return
if(usr.skygg==1)
usr.overlays += 'SmallDWFlame.dmi'
usr.DWP = usr.DWP*1.1
usr.attack = usr.attack*1.1
usr.defence = usr.defence*1.1
usr.DWarmor =1
if(usr.FOR)
usr.attack=usr.attack*2
if(usr.HI)
usr.DWP=usr.DWP*3
return
if(usr.stgg==1)
usr.overlays += 'SmallStormDWFlame.dmi'
usr.DWP = usr.DWP*1.05
usr.attack = usr.attack*1.05
usr.defence = usr.defence*1.05
usr.DWarmor =1
return
if(usr.sugg==1)
usr.overlays += 'SmallSunDWFlame.dmi'
usr.DWP = usr.DWP*1.05
usr.attack = usr.attack*1.05
usr.defence = usr.defence*1.05
usr.DWarmor =1
return
if(usr.mgg==1)
usr.overlays += 'SmallMistDWFlame.dmi'
usr.DWP = usr.DWP*1.05
usr.attack = usr.attack*1.05
usr.defence = usr.defence*1.05
usr.DWarmor =1
return
if(usr.rgg==1)
usr.overlays += 'SmallRainDWFlame.dmi'
usr.DWP = usr.DWP*1.05
usr.attack = usr.attack*1.05
usr.defence = usr.defence*1.05
usr.DWarmor =1
return
if(usr.cgg==1)
usr.overlays += 'SmallCloudDWFlame.dmi'
usr.DWP = usr.DWP*1.05
usr.attack = usr.attack*1.05
usr.defence = usr.defence*1.05
usr.DWarmor =1
return
if(usr.tgg==1)
usr.overlays += 'SmallThunderDWFlame.dmi'
usr.DWP = usr.DWP*1.05
usr.attack = usr.attack*1.05
usr.defence = usr.defence*1.05
usr.DWarmor =1
return
if(usr.dgg==1)
usr.overlays += 'SmallDarkDWFlame.dmi'
usr.DWP = usr.DWP*1.05
usr.attack = usr.attack*1.05
usr.defence = usr.defence*1.05
usr.DWarmor =1
return
bigflame
if(usr.skygg==1)
usr<<'DyingWill.wma'
usr.overlays += 'DyingWill.dmi'
usr.DWP = usr.DWP*1.7
usr.attack = usr.attack*1.5
usr.defence = usr.defence*1.5
if(usr.FOR)
usr.attack=usr.attack*2
if(usr.HI)
usr.DWP=usr.DWP*3
usr.icon_state="DW"
usr.DWarmor =1
return
if(usr.stgg==1)
usr<<'DyingWill.wma'
usr.overlays += 'StormDyingWill.dmi'
usr.DWP = usr.DWP*1.2
usr.attack = usr.attack*1.7
usr.defence = usr.defence*1.2
usr.DWarmor =1
return
if(usr.sugg==1)
usr<<'DyingWill.wma'
usr.overlays += 'SunDyingWill.dmi'
usr.DWP = usr.DWP*1.1
usr.attack = usr.attack*1.9
usr.defence = usr.defence*1.1
usr.DWarmor =1
return
if(usr.sforage==1)
usr<<'DyingWill.wma'
usr.overlays += 'DyingwillRage.dmi'
usr.DWP = usr.DWP*1.9
usr.attack = usr.attack*1.7
usr.defence = usr.defence*1.1
usr.DWarmor =1
return
if(usr.mgg==1)
usr<<'DyingWill.wma'
usr.overlays += 'MistDyingWill.dmi'
usr.DWP = usr.DWP*1.5
usr.attack = usr.attack*1.4
usr.defence = usr.defence*1.4
usr.DWarmor =1
return
if(usr.rgg==1)
usr<<'DyingWill.wma'
usr.overlays += 'RainDyingWill.dmi'
usr.DWP = usr.DWP*1.5
usr.attack = usr.attack*1.5
usr.defence = usr.defence*1.5
usr.DWarmor =1
return
if(usr.cgg==1)
usr<<'DyingWill.wma'
usr.overlays += 'CloudDyingWill.dmi'
usr.DWP = usr.DWP*1.4
usr.attack = usr.attack*1.5
usr.defence = usr.defence*1.4
usr.DWarmor =1
return
if(usr.tgg==1)
usr<<'DyingWill.wma'
usr.overlays += 'ThunderDyingWill.dmi'
usr.DWP = usr.DWP*1.4
usr.attack = usr.attack*1.4
usr.defence = usr.defence*1.5
usr.DWarmor =1
return
if(usr.dgg==1)
usr<<'DyingWill.wma'
usr.overlays += 'DarkDyingWill.dmi'
usr.DWP = usr.DWP*1.4
usr.attack = usr.attack*1.4
usr.defence = usr.defence*1.4
usr.DWarmor =1
return
Acro
usr<<'DyingWill.wma'
if(usr.skygg==1)
usr.underlays += 'AcroDWFlame.dmi'
usr.DWP = usr.DWP*2
usr.attack = usr.attack*3
usr.defence = usr.defence*3
if(usr.FOR)
usr.attack=usr.attack*2
if(usr.HI)
usr.DWP=usr.DWP*4
usr.DWarmor =1
return
if(usr.stgg==1)
usr<<'DyingWill.wma'
usr.underlays += 'AcroStormDWFlame.dmi'
usr.DWP = usr.DWP*2
usr.attack = usr.attack*2
usr.defence = usr.defence*2
usr.DWarmor =1
return
if(usr.sugg==1)
usr<<'DyingWill.wma'
usr.underlays += 'AcroSunDWFlame.dmi'
usr.DWP = usr.DWP*2
usr.attack = usr.attack*3
usr.defence = usr.defence*2
usr.DWarmor =1
return

if(usr.mgg==1)
usr<<'DyingWill.wma'
usr.underlays += 'AcroMistDWFlame.dmi'
usr.DWP = usr.DWP*3
usr.attack = usr.attack*2
usr.defence = usr.defence*2
usr.DWarmor =1
return
if(usr.rgg==1)
usr<<'DyingWill.wma'
usr.underlays += 'AcroRainDWFlame.dmi'
usr.DWP = usr.DWP*3
usr.attack = usr.attack*2
usr.defence = usr.defence*2
usr.DWarmor =1
return
if(usr.cgg==1)
usr<<'DyingWill.wma'
usr.underlays += 'AcroCloudDWFlame.dmi'
usr.DWP = usr.DWP*2
usr.attack = usr.attack*3
usr.defence = usr.defence*2
usr.DWarmor =1
return
if(usr.tgg==1)
usr<<'DyingWill.wma'
usr.underlays += 'AcroThunderDWFlame.dmi'
usr.DWP = usr.DWP*2
usr.attack = usr.attack*2
usr.defence = usr.defence*3
usr.DWarmor =1
return
if(usr.dgg==1)
usr.underlays += 'AcroDarkDWFlame.dmi'
usr.DWP = usr.DWP*2
usr.attack = usr.attack*2
usr.defence = usr.defence*2
usr.DWarmor =1
return
fire
if(usr.DWarmor)
usr.DyingWill -=50
if(usr.DyingWill <= 4)
usr.overlays -= 'SmallDWFlame.dmi'
usr.overlays -= 'SmallStormDWFlame.dmi'
usr.overlays -= 'SmallThunderDWFlame.dmi'
usr.overlays -= 'SmallMistDWFlame.dmi'
usr.overlays -= 'SmallRainDWFlame.dmi'
usr.overlays -= 'SmallCloudDWFlame.dmi'
usr.overlays -= 'SmallThunderDWFlame.dmi'
usr.overlays -= 'SmallSunDWFlame.dmi'
usr.overlays -= 'SmallDarkDWFlame.dmi'
usr.overlays -= 'DyingWill.dmi'
usr.overlays -= 'StormDyingWill.dmi'
usr.overlays -= 'SunDyingWill.dmi'
usr.overlays -= 'CloudDyingWill.dmi'
usr.overlays -= 'RainDyingWill.dmi'
usr.overlays -= 'DarkDyingWill.dmi'
usr.overlays -= 'MistDyingWill.dmi'
usr.overlays -= 'DyingwillRage.dmi'
usr.overlays -= 'ThunderDyingWill.dmi'
usr.underlays -= 'AcroDWFlame.dmi'
usr.underlays -= 'AcroStormDWFlame.dmi'
usr.underlays -= 'AcroThunderDWFlame.dmi'
usr.underlays -= 'AcroMistDWFlame.dmi'
usr.underlays -= 'AcroRainDWFlame.dmi'
usr.underlays -= 'AcroCloudDWFlame.dmi'
usr.overlays -= 'AcroThunderDWFlame.dmi'
usr.underlays -= 'AcroDarkDWFlame.dmi'
usr.DWarmor = 0
usr.icon_state=""
usr.attack = usr.mattack
usr.DWP = usr.mDWP
usr.defence = usr.mdefence
return
else
sleep(4)
goto fire
else if(usr.DWarmor)
usr.overlays -= 'SmallDWFlame.dmi'
usr.overlays -= 'SmallStormDWFlame.dmi'
usr.overlays -= 'SmallThunderDWFlame.dmi'
usr.overlays -= 'SmallMistDWFlame.dmi'
usr.overlays -= 'SmallRainDWFlame.dmi'
usr.overlays -= 'SmallCloudDWFlame.dmi'
usr.overlays -= 'SmallThunderDWFlame.dmi'
usr.overlays -= 'SmallDarkDWFlame.dmi'
usr.overlays -= 'SmallSunDWFlame.dmi'
usr.overlays -= 'DyingWill.dmi'
usr.overlays -= 'StormDyingWill.dmi'
usr.overlays -= 'SunDyingWill.dmi'
usr.overlays -= 'CloudDyingWill.dmi'
usr.overlays -= 'RainDyingWill.dmi'
usr.overlays -= 'DarkDyingWill.dmi'
usr.overlays -= 'MistDyingWill.dmi'
usr.overlays -= 'ThunderDyingWill.dmi'
usr.underlays -= 'AcroDWFlame.dmi'
usr.underlays -= 'AcroStormDWFlame.dmi'
usr.underlays -= 'AcroThunderDWFlame.dmi'
usr.underlays -= 'AcroMistDWFlame.dmi'
usr.underlays -= 'AcroRainDWFlame.dmi'
usr.underlays -= 'AcroCloudDWFlame.dmi'
usr.overlays -= 'AcroThunderDWFlame.dmi'
usr.underlays -= 'AcroDarkDWFlame.dmi'
usr.DWarmor =0
usr.icon_state=""
usr.defence = usr.mdefence
usr.attack = usr.mattack
usr.DWP = usr.mDWP


But Why The one i posted above doesn't even though I tried the same thing. I even Changed the DWarmor To CannonU

I Want it in the Click() Even if its messy since that how i need it.

So Any Clues why its not working you don't have to write the code 4 me just give me a hint why.

Cause I tried for the past 3days to get this to work e.o

Thanks
Why do you have usr.froze and use.Frozen?
.froze From Ice Attack, user. Frozen is When Player...is frozen XD.

anyway, I Tripe Triple Check and Changes some things and i got it to work I'll Thanks Albro1 since he gave me some good advice.

In response to XIIIGaming
XIIIGaming wrote:
well that code wasn't what i was looking 4
It wasn't meant to be. I was showing you the concept.

I Want it in the Click() Even if its messy since that how i need it.

You need to understand the use of procs. You can do the same thing as you are doing here in a much neater way. You should not be using goto. Never use it. Unless there is absolutely no better way to do it. Which is next to never.

obj/Click()
do_stuff(usr)

obj/proc/do_stuff(mob/m)
// do stuff here.


That's the general concept.
Just A question, Not Trying to Sound like Smart a$$. Just Wanna know. what wrong with goto is there a reason? :S just wondering. you know for future reference
In response to XIIIGaming
XIIIGaming wrote:
Just A question, Not Trying to Sound like Smart a$$. Just Wanna know. what wrong with goto is there a reason? :S just wondering. you know for future reference

It's outdated and inefficient compared to other ways. It is typically looked down upon to use it because there is almost always a better way to do whatever you are trying to do. More readable ways as well. With goto, you have to scroll back and forth through your code just to see what is going on.
I see. Thanks
Ive heard that goto also doesnt end the process, that it just pics up everything behind it; whereas having a function -like data structure is better because it automatically erases irrelevent data after each "function" ("function" is just a general term, here it means proc) Is that correct?
The issue with Goto is basically this;

GOTO TAG 1
Some Code
GOTO 2
Some more code.

GOTO TAG 2
Some code
IF [something]
Some code.
GOTO 1

The BOLD code might never actually get executed.

If you have a goto in the middle of a function, then it becomes possible for the code being 'executed' to move out of that function without the function finishing.
This makes it a lot harder to debug code, because you're constantly bouncing around the code, rather than executing it logically, top-to-bottom. It can also cause very strange behaviour, where variables don't get created, or set properly ( because a goto just skipped that code entirely. )