ID:169911
 
How could I add a var during gameplay that stays the whole game? Cause I want to have employees, and each time you hire one I want it to add a new var... mob/var/[employees + 1] But that only works temp. How can I make it a perm var?
Strawgate wrote:
How could I add a var during gameplay that stays the whole game? Cause I want to have employees, and each time you hire one I want it to add a new var... mob/var/[employees + 1] But that only works temp. How can I make it a perm var?

If you have a save game code that will save the info u can do this

mob
var/employees=0


If you want to add employees to the number, put this in
    usr.employees+=1

//usr.employees-=1
//to subtract employees
In response to ElderKain
Nonono.. What I want is not to add to the var, but to create a new one. that lasts untill the person logs out.
In response to Strawgate
Strawgate wrote:
Nonono.. What I want is not to add to the var, but to create a new one. that lasts untill the person logs out.

Then put it in a logout code to set it to 0 then like this.
mob
Logout()
src.employees=0
del(src)


that way when the user logs out then back in it will be set back at 0 so even if they saved, it will be set back to zero,

and as a second action, incase the Logout() proc doesn't catch it...
client
Del()
src.employees=0

Just in case of a crash and it doesn't go through the normal logout process.

<font size=1>Note: I might not know exactly what i'm talking about in the coding, its just a suggestion.</font>
In response to ElderKain
mob
var/tmp/employees
verb
Makeemp()
usr.employees ++


Making it a tmp var is all i can think of, i'm not sure about creating one on login :\
Strawgate wrote:
How could I add a var during gameplay that stays the whole game? Cause I want to have employees, and each time you hire one I want it to add a new var... mob/var/[employees + 1] But that only works temp. How can I make it a perm var?

The best way to do this is with an associated list. Now I'm going to do this right, all sorts of people talked to me about these things when I was a newbie, but nobody explained what they did or how to use them. First, associated lists are like normal lists, but you can attach a value to them. In this case, the list marker is going to be the number of the employee. The associated value is going to be a reference to the mob of the employee.

mob/var/employee[] = list()

mob/verb/hire(msg as text)
var/mob/employee/M = new() // Create the employee
M.name = coptext(msg, 1, 20) // To keep the name short
var/employee_id = src.employee.len // This sets the employee idea so that it's the value after the last one in the list
src.employee += list(employee_id=M)
src << "You hired [M] as employee #[employee_id]!"


Now, something a bit confusing about associated lists is how you access the two elements, which are, in our case, the employee ID# and the employee mob itself. Just for programming lingo, the ID# (or the list marker, whatever is on the left of the equal sign in list()) is known as the INDEX for the list. To access the index and see what number an employee is, you use

for(var/X in employee)
src << "The employee ID# is [X] and the employee is [employee[X]]"


As you can see, we accessed the value of both the ID and the mob itself, the mob was accessed by using a method I call "index pointing", where you put listname[index] and it will retrieve the value.

Hopefully this made at least a little sense, I'm not a very good teacher.


~Polatrite~
In response to Polatrite
Also, to add onto that. You can also use the same old number indexing for it as well.

for(var/i=1,i<=List.len,i++)
var/mob/M=List[i]
if(M)
//blah


Or:

for(var/X in List)
var/mob/M=List[X]
if(M)
//blah


Of course, either one will work. But, the first one is generally more suited towards something needing a counter of some sort. Like maybe sorting associated lists, or junk.
In response to ElderKain
I dont have a saving system... so it doesnt matter...
In response to Polatrite
Is there anyway to have a verb that includes the Employee list, there job, there pay, and there productivity?