ID:1954275
 
(See the best response by Super Saiyan X.)
Code:
var
Month=0
Year=0

proc
Time()

while(1)
sleep(100)
Ageing()

global.Month++
world<<output("Repop(Ageing): <b> Month:[Month] - Year , [Year]</b>","chatOutput")
if(global.Month==12)
global.Month=0
global.Year++


mob/proc
Ageing()
var/player/p=src
if(!p)
return
else
while(p.logged)
p.age+=0.1


world<<output("It is now Year:[Year], Month:[Month]","chatOutput")


Problem description:

Pretty self explanitory of what I'm trying to do here, is there a certain type to call for mob procs in global procs? Like for that specific line.

proc
Time()

while(1)
sleep(100)
Ageing()// It gives me an error at Compile: Ageing Undefined Proc



I've never really understood global procs and global vars intertwine with mob vars and mob procs if that makes any sense.

Pretty self explanitory of what I'm trying to do here, is there a certain type to call for mob procs in global
It may not be to everyone who wants to offer help, so you should still explain.


... are you trying to call the Ageing proc for every mob?
Loop through your list of players (or all clients on the server), call the proc on their mob.
proc
Time()
while(1)
sleep(100)
Ageing()

global.Month++
world<<output("Repop(Ageing): <b> Month:[Month] - Year , [Year]</b>","chatOutput")
if(global.Month==12)
global.Month=0
global.Year++
for(var/mob/M in world)
M.Ageing()


This would age every mob in the world, like SSX said its best to have a list to hold all your players
I'm trying to call mobs under /player, although in this source, once an official character is created the src default type turns to /player.

I repeat, are you trying to call the Ageing proc for every player on the server?

If so, that's literally what you do. You iterate over every player and call the proc.


Colesprite wrote:
proc
Time()
while(1)
sleep(100)
Ageing()

global.Month++
world<<output("Repop(Ageing): <b> Month:[Month] - Year , [Year]</b>","chatOutput")
if(global.Month==12)
global.Month=0
global.Year++
for(var/mob/M in world)
M.Ageing()

This would age every mob in the world, like SSX said its best to have a list to hold all your players

Just an FYI, you should probably never loop through all mobs - all mobs includes NPCs, not just players. If there is no data structure to hold all the players, you can loop through all the clients, and call the proc on the client's mob. Or, since he says his players all have a /player type, you can iterate over that.
My new code:

proc
Time()
while(1)
sleep(100)
global.Month++
world<<output("Repop(Ageing): <b> Month:[Month] - Year , [Year]</b>","chatOutput")
for(var/player/p in world)
if(p.key in WipePlayers)
p.Ageing()
if(global.Month==12)
global.Month=0
global.Year++


Got no compile errors, but now every Repop I get a screen-freeze & My Dream Seeker becomes Non-Responsive.

This only happens once my player officialy creates a character and has it's key stored in my list of players.

I'm not sure if it has anything to do with the way how I called it, or if it's the way I called in for New()

world/New()
..()
spawn() Time()
for(var/player/M in world)
spawn() M.system.Save(M)
That's because your ageing proc has a while loop in it, that will run forever, because I'm assuming p.logged is never a false value.
P.logged is a default-false value, it becomes true upon finishing creation.

And ooooooooohhhhh, so only Time should have the while loop?
In response to HaxRp
Best response
HaxRp wrote:
P.logged is a default-false value, it becomes true upon finishing creation.

And ooooooooohhhhh, so only Time should have the while loop?

Yes. I'm assuming your while loop in Ageing() should be an if statement.

Time is a global ticker.
You call that when you create your world.
Time is constantly running in the background and incrementing time. (though your interval is kind of...low...time might be increasing a bit too fast).

When time changes, you iterate over every player in the world to call Ageing, which will increase their age. It doesn't need a loop, since Ageing is called by Time.
Ahhhhh, and it finally works :D

proc
Time()
while(1)
sleep(100)
global.Month++
world<<output("Repop(Ageing): <b> Month:[Month] - Year , [Year]</b>","chatOutput")
for(var/player/p in world)
if(p.key in WipePlayers)

p.Ageing()
if(global.Month==12)
global.Month=0
global.Year++


mob/proc
Ageing()
var/player/p=src
if(!p)
return
else //for() //loop this action

p.age+=0.1
world<<output("It is now Year:[Year], Month:[Month]","chatOutput")




be aware, your years have 11 months. and, I'm not entirely sure why you're doing all that stuff in Ageing, aside from incrementing the age.

Aside from your code being functional, this probably isn't the best way to deal with time.
Can you suggest a more proper version perhaps? Thanks for the feedback .
Ter13 has a good example here: http://www.byond.com/forum/?post=1586003#comment10331426

This can easily be adapted to handle months as well.

The idea is that each player has a birth time. There is a single loop that increases the time during the month. Rather than increment the player's age, their age is recalculated based on the world's current birth time.
That means, if a player is offline for a while, their character will age properly when they log in.

This also lets you manually change the world's time as well, and then every player's age is changed based on that.
Removing loops through world will give you better performance in the long run as you add more things to your game. Consider using global lists to store things you want to loop through to increase performance at the cost of a little memory.
In response to Clusterfack
Clusterfack wrote:
Removing loops through world will give you better performance in the long run as you add more things to your game. Consider using global lists to store things you want to loop through to increase performance at the cost of a little memory.

I'm learning more and more how to contain lag, and increase better/smoother performance everyday, thank you.