ID:141265
 
Code:
world
New()
..()
spawn(150) Age1()
mob/var
age=0
deathage=0
year=0
powerlevel_max=0
ki_max=0
strength=0
speed=0
defence=0

proc/Age2()
spawn(72000) Age1()


proc/Age1()

src.year+=1
world<<"It is year [year].."
src.ki_max+=rand(1,15)
src.powerlevel_max+=rand(5,15)
src.strength+=rand(1,15)
src.speed+=rand(1,15)
src.defence+=rand(1,15)


Problem description: I don't know if I'm setting the age right, I'm aiming to make it to where the server itself will display a year and keep going while the server is running. Player is still gaining age even if logged out, it might not work but the error is that I have undefined variables when they're listed above as a variable.

The reason you get "undefined variable" errors is because the variables don't exist.

If you look at your code, specifically the "Age1" proc, you will see that you are trying to change the "year", "ki_max" and "powerlevel_max" (among others) of the "src" object.

What is "src"? In this case, it is moot-- the proc is not attached to the mob, so it will not share its variables.

Changing proc/Age1() to mob/proc/Age1() will cause your "undefined variable" errors to vanish, but new errors will pop up: both world/New() nor proc/Age2() can call Age1() because it is no longer a global proc.

What you want to do here is do a so-called for loop, where you loop through every mob and call it's "Age1" proc.

for(var/mob/M in world) M.Age1()

mob/proc/Age1()
src.year+=1
src << "It is year [year].." //changed from "world" to "src" because it would otherwise spam the world
src.ki_max+=rand(1,15)
src.powerlevel_max+=rand(5,15)
src.strength+=rand(1,15)
src.speed+=rand(1,15)
src.defence+=rand(1,15)


Whilst the above will fix your problems, it will not fix your design issues. Your system is based upon a year. Every so often (every 7200 seconds), the year is increased and you want players to automatically become a little bit stronger.

Without further ado, I give you a working system. I'm just going to hope you're going to actually read it through and learn from it:

var/gameYear
world
New() //when the world starts up
. = ..()
//retrieve the current year from file
gameYear = file2text("year.txt")
if(gameYear)
gameYear = text2num(gameYear)
else
gameYear = 2009 //we'll assume you start at the year 2009
spawn AgeLoop()
Del() //when the world shuts down (or reboots)
//save the current year to a file called "year.txt"
if(fexists("year.txt")) fdel("year.txt")
text2file(num2text(gameYear), "year.txt")
return ..()

proc
AgeLoop()
//this is an infinite loop using while.\
it will loop forever, without the need of calling some proc over and over

while(1)
sleep(72000)
world << "Another year has passed. It is now [++gameYear]."
//the output above uses ++gameYear to increase gameYear by 1 BEFORE outputting it\
this saves us the need of putting "gameYear += 1" somewhere

for(var/mob/M in world) //loop through every mob
M.ProcessAge() //call the ProcessAge proc

mob/proc/ProcessAge()
ki_max += rand(1,15)
powerlevel_max += rand(5,15)
strength += rand(1,15)
speed += rand(1,15)
defence += rand(1,15)
In response to Android Data
Hmm, it confuses me but helps me at the same time..I'll try and learn from it, thank you.
In response to Element88
Element88 wrote:
Hmm, it confuses me but helps me at the same time..I'll try and learn from it, thank you.

You're welcome. If you have any questions about my snippet, just reply and ask what you don't understand. One of us will be bound to answer you. :)
In response to Android Data
Thanks a lot bro, quick answers also. I appreciate it. ;D