ID:2171794
 
(See the best response by Kaiochao.)
Code:
            verb/Quest()
set name="Start Quest"
set category="Quests"
set src in oview(1)
if(usr.canQuest)
canQuest=0
usr.inQuest=1
usr.NonPK=0
usr.cansave=0


Problem description:
I'm having this problem where.. I'm a terrible coder x.x. but really, how this code works, is when someone starts the quest, everyone's "canQuest" should turn to 0 so nobody can enter the quest, but it isn't changing anyone's canQuest D:. I thought not putting anything before canQuest(ex. 'usr'.canQuest/'src'.canQuest ect.) changes everyone in the world's canQuest var to 0, am I wrong? T.T. Anyone have better ideas?
to change the canQuest variable of every player in the world, you'd probably want to use a for() list.

ex:
for(var/mob/player/M in world) //loop through all of the online players. change this path to whatever your default player mob is
if(M!=usr && M.client) //verifies that M is actually a player, but not the verb's user
M.canQuest=0


more info about the for proc and how it works:
http://www.byond.com/docs/ref/info.html#/proc/for
I looked at the link, it just confuses me I can't make sense of it lol. but idk what to replace player with, I just use

for(var/mob/M in world)

I've never used anything else. I'm new D: XD. Be kind T.T.
if I take out player will it still loop through all online players?
if you don't use a specific path for the mobs belonging to players then that should work fine.

basically what for() does, in this scenario, is cycle through all of the entries within a list that match the path or variable you assigned to it (in this case, the players within the world) - allowing you to define a variable or initialize a proc for all of them at once.

the main reason i would suggest defining a separate mob type specifically for players is because cycling through every mob in the world within for() can use a lot more memory than necessary - and if you have a big game with a lot of mobs that extra processing power can really add up and cause your game to lag.

So, down the road I might make a separate mob for players, but I tried what you suggested, and maybe... probably I did something wrong lol, but it isn't working. here,
                for(var/mob/M in world) //loop through all of the online players. change this path to whatever your default player mob is
if(M!=usr && M.client && M.inQuest && !usr.canQuest)
usr<< "Someone is in the quest!"
return
else
M.canQuest=0
usr.canQuest=0
usr.inQuest=1
usr.NonPK=0
usr.cansave=0

I tried this with two of my own keys, and both could enter the quest at the same time, even though after key1 entered, key2's canQuest should be 0, not allowing it to enter.
you'd want to check to make sure nobody else is in the quest before you'd call for(). the context of this for proc is to cycle through players and make it so they can't participate in this quest, right? if so, then you'd want to first: verify the user is allowed to participate, second: assign the user's variables and activate the quest, then finally cycle through the rest of the players and disable them from entering this quest.

just try to slow down and think about what order you want everything to happen.
        if(!usr.canQuest||usr.inQuest)
usr<< "Someone is in the quest!"
return
usr.canQuest=0
usr.inQuest=1
usr.NonPK=0
usr.cansave=0
for(var/mob/M in world)
if(M!=usr && M.client)
M.canQuest=0
omg your right! It works! You are so smart :D. Thank you ^^.
Having to loop through all the mobs in the world is just a bad idea in general.
for(var/client/c)
if(c.mob)
c.mob.canQuest = 0


This is a more ideal way of doing this.
Okay, I'll try that too! But for training purposes, why is it a bad idea to loop through all the mobs? Does it cause more lag?
When you don't put anything before a variable, DM checks for variables in order of closest scope; for example, it might first check for a matching local variable, then an instance variable (a variable belonging to src), then a global variable.
mob
// every mob instance has their own instance of this variable
var blah = 123

verb
blah()
src << blah // outputs 123
src << src.blah // same as above

bloop()
// every instance of this proc has its own instance of this variable
// (a proc instance exists between the time it's called and the time it returns)
var blah = 456

src << blah // outputs 456
src << src.blah // outputs 123

I'm a bit confused on why you want to change everyone's canQuest. If everyone should always have the same canQuest value, then it should be a global variable.
mob
var
global
// every mob shares the same instance of this variable
canQuest = TRUE

verb
quest()
if(canQuest)
src << "Starting a new quest."
canQuest = FALSE
// etc.

else
src << "Can't start a new quest."
Well no, the point is so that only one person can enter the quest at a time.. so when 1 person enters, everyone else is restricted.
In response to Kyubikitsune
Best response
Then, shouldn't it be a variable of the quest-giver? The quest-giver determines whether or not someone can receive his quest. You shouldn't make every player keep track of whether or not they can receive a quest from this particular quest-giver. What if you want multiple quest-givers?
mob/quest_giver
var
can_offer_quest = TRUE

verb
talk()
set
src in view(1)
category = "Quest"
name = "Start Quest"

if(can_offer_quest)
can_offer_quest = FALSE
usr << "[src]: Quest started."

// etc.

else
usr << "[src]: Someone else is doing my quest."
That's such a great idea I never even thought about that T.T. Thank you!