ID:2216375
 
(See the best response by Ter13.)
Code:
mob/player
proc
getnextskill()
var/tmp/nextskill = lowertext(src.role)
nextskill = text2path("mob/role/[nextskill]")
nextskill = nextskill.skillset

mob/player/role/testclass
name="Testclass"
skillset = list("Testskill@6@5@Element@Type","Second@10@3Element@Type")


Problem description:
Evening guys, I'm back with a terribly newbie question(maybe as newbie as I): I am trying to access a variable from another mob as mob/player, namely mob/player/roles/[insertrandomrole]/skillset. I made a script so that I can extract stuff from a list the way I want to.

PS: Error is always code\tests.dm:8:error: nextskill.skillset: undefined var.
Why not just do:

/mob/player/role/getnextskill()
return skillset
Sry, my fault for not posting the whole thing. Here it goes:

mob/player
proc
getnextskill()
var/tmp/nextskill = lowertext(src.role)
nextskill = text2path("mob/role/[nextskill]")
nextskill = nextskill.skillset


nextskill=list("Intervene@6@5@Fauna@Physical","Taunt@10@3@Erupt@Mental") //needs to be replaced with real skilllist

var/tmp/nskill
for(nskill in nextskill)
nskill=splittext(nskill,"@")
if(text2num(src.level) < text2num(nskill[2]))
nextskillHUD.maptext = "[nskill[1]] <b>Level:</b>[nskill[2]] <b>Element:</b>[nskill[3]] [nskill[4]] <b>Type:</b> [nskill[5]]"
return
nskill="<b>None</b>"
nextskillHUD.maptext = nskill


Basically, I want to change the name of the next skill in the stat window and stylize it so it fits nicely. What I currently have there is a placeholder list to see if I can get the vars out nicely.

The player has control of mob/player, yet I made mob/player/role/[actualrole] to put all the vars belonging to a class where I can easily find it and class changes will be a fun little game mechanic if I get this game done. Hopefully. I have the bad habit of trying to do stuff that exceeds me, you see...
Best response
The player has control of mob/player, yet I made mob/player/role/[actualrole] to put all the vars belonging to a class

Object-oriented hierarchy is not a database.

Store the information in a datum.

class
var
id
name
list/skills


Initialize one of each class on world startup and store them by id.

var
list/classes
class_manager/class_manager = new() //happens before world.New()

class_manager
New()
classes = list()
var/class/c, id
for(var/t in typesof(/class)) //loop through all types of /class and initialize one of each.
c = t
if(id = initial(c.id))
classes[id] = new t()


You can now indirectly reference the class in one of two ways:

1) reference the class by id and use the global.classes list each time you want to access the class.

the setup:
class/fighter
id = "fighter"
name = "fighter"

mob
var
class = "fighter"


the lookup:
var/class/c = classes[class]


2) reference the class by id only when the mob is saved, and otherwise, on mob initialization store a reference to the class object.

mob
var
tmp/class

Read(savefile/F)
..()
F["class"] >> class
class = classes[class]

Write(savefile/F)
..()
F["class"] << class.id


Using this structure, you should be able to sidestep your question completely and use a much more reasonable setup for defining classes.


Essentially, you should not be using the object-oriented hierarchy to define attacks and classes under /mob, because classes are not a subtype of mob. These class datums are pure information containers that are intended to be used as singletons.
Thanks for the tip, I'm trying to get started with datums, but I'm still very far from understanding them fully. So, recently I tried that script out but I'm still not able to get the vars out of it that I want ^^''

role
var
id
name
skillset

var
list/roles
role_manager/rolemanager=new()

role_manager
New()
roles=list()
var/role/r, id
for(var/t in typesof(/role))
r = t
if(id==initial(r.id))
roles[id] = new t()

role/guide
id="guide"
name="Guide"
skillset = list("Upwind@3@2@Anima@Mental", "Path@6@5@Anima@Mental", "Zephyr@13@3@Anima@Mental")

Write(savefile/F)
..()
F["role"] << role.id
role = roles[role]

Read(savefile/F)
..()
F["role"] >> role


It gives me this tho:
code\login.dm:108:error: role.id: undefined var

Sorry to be bothersome, besides.
code\login.dm:108:error: role.id: undefined var


This error occurs because src, the role object, has no role variable to access.

Ter13's setup handled the saving of classes/roles under the mob the role belonged to (which makes sense). When a player saved, the id of their class/role was saved, so that when they loaded later on, said id could be used to restore the class/role using the global associative list, classes.

Some of your logic is wrong where this is concerned. Take a better look at the differences in what he wrote, and what you wrote.
Don't worry, I wrote the role var in another file handling all of the roles for mob/player.Furthermore, even when I try to copy and paste his script just as it is, I get that error.
In response to Kayren
Kayren wrote:
Don't worry, I wrote the role var in another file handling all of the roles for mob/player.Furthermore, even when I try to copy and paste his script just as it is, I get that error.

That's because you put the Write/Read functions under the wrong object.

And my message does have a minor mistake.

class should be defined on /mob as tmp/class/class to cast it as a class datum.