ID:177588
 
I have lots of vars for the players characthers and if I understood all right, as they are declared under /mob, all mobs, including NPC's will also have them. Is there any way to set up a vars for players only? Maybe an "If (isplayer)" under /mob/var [I dunno how to code this]?
I think that cleaning up the amount of var for only those who will really need them will reduce the lag and processing, making the game faster...Ain't I right?
Can someone help me please?
Regards
Leandro
If you want only players to have the vars, they have to be defined under mob/Player. Then, have all players mobs be mob/Player/(Whatever) or just mob/Player
In response to Garthor
Right. And to make sure all players are of type /mob/Player, set world.mob equal to /mob/Player.
In response to Air Mapster
I placed the vars under mob/Player/var
Then, no proc found them anymore
I placed the procs under mob/Player/proc but they still can't find the vars
Why? Am I missing something?
Regards
Leandro
In response to Leahn
I will try to be more specific
(Why programming in BYOND is so difficult?)
I am using some vars under /mob
They are vars for all (mob and players)
and I am using some vars under /mob/player
They are vars used for level ups and save checks
There are some procs and verbs that are only used under some circunstances than I placed then nor under /mob or /mob/player but under nothing like

verb
kick

and so on

Any proc or verb under /mob cannot find the vars under /mob/player and the procs and verbs under nothing cannot find any var

How can I address the vars?
In response to Leahn
Are you referring to the variable in the form 'src.varname' (or possibly 'varname' if it is not defined in a more local structure)?
In response to Leahn
Leahn wrote:
I will try to be more specific
(Why programming in BYOND is so difficult?)

BYOND is actually a very easy language, from what I hear.

I am using some vars under /mob
They are vars for all (mob and players)
and I am using some vars under /mob/player
They are vars used for level ups and save checks
There are some procs and verbs that are only used under some circunstances than I placed then nor under /mob or /mob/player but under nothing like

verb
kick

and so on

Any proc or verb under /mob cannot find the vars under /mob/player and the procs and verbs under nothing cannot find any var

Procs that are under "nothing" are called global procs.

How can I address the vars?

For the first problem, I'm assuming you have a setup like this:
mob/player
var/exp = 0
var/exp_needed = 0
var/level = 0

mob/proc/LevelCheck()
if(exp >= exp_needed)
level += 1

If your setup looks like that, then you're going to need to do a bit of changing. For example, why not redefine LevelCheck() for players? Example:
mob/proc/LevelCheck()  //this proc normally does nothing

mob/player/LevelCheck() //but we redefine it for /mob/player, so when a player calls it, it does something different
if(exp >= exp_needed)
level += 1

The second problem is about global procs. You're going to need to either use args or search for the mobs you want, since there is no src for global procs. You can't have global verbs, either. So let's say you have a proc like this:
proc/MyProc()
usr.somevar = 24

It is a very bad idea to use usr, because you don't know who's calling the proc. Instead, you could add an argument to MyProc() and stick the mob in there. For example:
proc/MyProc(mob/M)
M.somevar = 24

mob/verb/CallMyProc()
MyProc(usr)

You can use any number of args you want. For example, let's say you wanted an Attack command.
proc/Attack(mob/attacker,mob/defender)
view(attacker) << "[attacker] attacks [defender]!"
defender.HP -= rand(1,10)

mob/verb/attack(mob/M in oview())
Attack(usr,M) //call the proc

Even better, you can used named arguments so you don't have to put them in order.
mob/verb/attack(mob/M in oview())
Attack(attacker = usr,defender = M)

Named arguments are nice because they let you know which arg is which. Remember that named arguments don't work for most predefined procs, but they will always work for the procs you define.
In response to WizDragon
WizDragon wrote:
BYOND is actually a very easy language, from what I hear.

BYOND is very confusing, guy. Very very confusing...I mastered Lingo in less time...

For the first problem, I'm assuming you have a setup like this:
mob/player
var/exp = 0
var/exp_needed = 0
var/level = 0

mob/proc/LevelCheck()
if(exp >= exp_needed)
level += 1

If I setup like this, it won't find the vars needed and this is my problem. As I said, procs and verbs which are not under the same "tree" level do not find the other vars. Will it be solved by resolving who is calling like

verb/attack(mob/attacker,mob/defender)

?

You can't have global verbs, either.

Why not? I have some verbs added or subtracted under circunstances like classes and so on. Where should I place them that they would not appear under any stat panel until needed?

Named arguments are nice

I agree...Maybe I will rewite the code to use them...if I handle to solve the problem with the vars...

Regards and many thanks
Leandro