ID:148893
 
I was wondering how exactly would I turn this into a global var so that when I choose BattleOn() it lets everyone have fight = 1. This current code only lets "me" have the verb. Actually dont mind usr cause I put that there for no reason, but im not sure how to do this. (never used a global var in my life)



mob/verb/BattleOn()
set category = "Admin"
usr.fight = 1
world<<"Battle Mode has Begun!"

mob/verb/BattleOff()
set category = "Admin"
usr.fight = 0
world<<"Battle Mode has Ended"

Branks wrote:
I was wondering how exactly would I turn this into a global var so that when I choose BattleOn() it lets everyone have fight = 1. This current code only lets "me" have the verb. Actually dont mind usr cause I put that there for no reason, but im not sure how to do this. (never used a global var in my life)

var/fight = 0 // Declares global Varible
mob/verb/BattleOn()
set category = "Admin"
fight = 1 // changes the global varible fight to 1
world<<"<font size = 5><font color=red>Battle Mode has Begun!</font color=red></font size = 5>"

mob/verb/BattleOff()
set category = "Admin"
fight = 0 // changes the global varible fight back to 0
world<<"<font size = 5><font color=red>Battle Mode has Ended</font color=red></font size = 5>"
If you want to set a gobal variable, then simply define it as

var/yourvariable


Do this at no indentation so that it's not under any mobs, objs, etc. Then, simply use yourvariable = value anywhere in your code to set it.

var/fight

mob/verb/BattleOn()
set category = "Admin"
fight = 1
world<<"<font size = 5><font color=red><b>Battle Mode has Begun!</b></font color=red></font>"

mob/verb/BattleOff()
set category = "Admin"
fight = 0
world<<"<font size = 5><font color=red><b>Battle Mode has Ended</b></font color=red></font>"
In response to Darkness
Sweet! it worked perfectly, thans to both of you who helped
In response to Darkness
it only activates the verb for me and not the entire world
In response to Branks
Do you have a fight var with mob's too? If so the compilation might get confused.
In response to Super16
No justthe one var which is over the BattlOn verb
In response to Branks
Well, what are you trying to do with the variable? You have to have everything which is affected by the variable check for it. For example, if by setting fight = 1, everyone can fight, then their attack code must check the variable

mob/proc/fight(var/mob/M in oview(1))
if(!fight) //checking the var we set earlier
return //If it's not true (ie, 0), do nothing
else
//fight code


Hope that helps