(See the best response by Nadrew.)
This is the affinity system which the NPC will keep a list of players of whom he likes the most,
whoever is at the top of that list will get a special quest from that NPC or a Item whichever the NPC is willing to give.

affinityListNames = newlist("NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL")//This is the list that every NPC will have that will have the players names stored in.
affinityListAffin = newlist(0,0,0,0,0,0,0,0,0,0)//This is the affinity Levels which corresponds with the location of the name in the other list.
for(var/i = 1 to affinityListAffin.len)

Problem description:

Im pulling my hair out because i try to follow the guides and im getting errors left and right. idk if its just because i dont really understand this language completely yet but what im trying to do is to have NPCS keep a list of players that they like its an affinity system. And i want them to be checking that list to see who is at the top of the list and when they next talk to the NPC they will recieve something special.

I am getting an error at affinityListAffin.len
Best response
Firstly you need to cast them as lists to access their list variables and functions at compile-time,


Next, you don't want newlist() here, just list().

var/list/mylist = list()
// or
var/list/mylist = new()
// or

You don't need to initialize any elements here since you'll be adding data per-player.

Next, you'll probably want an associative list instead of two lists.

var/list/mylist = list("Name"=10,"Name2"=20)

This would make mylist["Name"] come out as 10, so you'd just add the player's name to the list, then use the associated value to determine the affinity. You can also loop directly over the contents of a list without using another variable.

for(var/I in mylist)
src << "[I] = [mylist[I]]"

This would output

Name = 10
Name2 = 20

Using the above list.

For adding and removing from the list, you can simply use +=, but since we're gonna be using associated values, you don't even need to go that far.

mylist[] = 0

Would add src's name to the list with an associated value of 0.

And for changing/setting the value it's as easy as

ChangeValue(newvalue as num)
mylist[] = newvalue

And removing is as easy as

mylist -=
I will put that in later thanks so much for the suggestion.
I will ask more questions later.
My idea works for now as a global variable, Now can i make classes in this language and have each NPC have their own private lists and have access to the procs to change value and to add
Your original method of putting the variables within the /mob/NPCs/interactive was on the right track.

var/some_var = 10

some_var = 20

some_var = 15

some_var = 25

caller << "[src]'s some_var is [src.some_var]"

Then if you call the object's ShowValue(), passing the player through the argument

mob/verb/Test(obj/parent/P as obj in view())
if(istype(P,/obj/parent)) // just in case

You'll get a different value based on the type of the object, all objects under a parent will share its procs and variables, you can override the procs and call the parent of that proc with ..()
So with that all NPC'S will have their own lists containing players and their affinities towards them? Can you explain a little more please.
Variables defined under a specific type will be individual to objects created of that type, so yes, each NPC would have their own list.

How you save and load that data is up to you though.
What if i saved it in a save file in the server but how would i put it back in the NPC?
You'd either want to save a list of the NPCs (not recommended because you'd have to save them all anytime you needed to save one), or give them some kind of unique identifier and save them the same way you would a player, using that identifier instead of something like ckey.
Can i use their appointed names?
If said name is unique to that NPC and nothing else, and you'd likely want to strip it down to a file-name-friendly format using ckey()
I ended up having the players keep a list of the NPC's names and their affinity towards them. And it will be in the player's save file so the NPCS wont need a save file using more space and more cpu.