ID:2218101
 
(See the best response by Kaiochao.)
Code:
mob/Login()
var/mob/player/p = new()
p.loc = locate(3,3)
p.client = src.client

mob/player
proc
classchange()

mob/player
var/role/playerrole = /role/hunter
verb/roletest()
playerrole.getrolename()

role/hunter
id="hunter"
name="Hunter"

role
var
id
name
skillset
proc/getrolename()
src << name


Problem description:

Sup guys, just me spamming the developer help like the typical newbie. I've been reading around the whole forum for infos on datums and now tried to use them aswell, but I seem to just not understand it.

Currently, I am trying to access a proc so it returns the var inside the datum I want to get at. While compilation works flawlessly, I get a runtime error, which is bothersome.

And here is the error:
runtime error: Cannot execute /role/hunter (/role/hunter).getrolename().
proc name: roletest (/mob/player/verb/roletest)
source file: datumhandling.dm,13
usr: (src)
src: the player (/mob/player)
src.loc: null
call stack:
the player (/mob/player): roletest()
Best response
Compilation succeeds because the declared type of the playerrole variable, /role, implies that the variable contains a reference to an object instance that has a proc called "getrolename()" (and all the other vars and procs of /role).

However, the value of the variable does not, because the procs defined under a type are only accessible to instances of that type, not to the type itself.
var/role/playerrole = new/role/hunter

It's strange that you would know how to instantiate the player in Login() in order to access its variables, but you didn't think to instantiate the role.

Also, since you claim compilation works flawlessly, I assume the first bit of the snippet isn't actually in your code, otherwise you'd not only have a compiler error on locate(3,3) (locate() takes 1 or 3 arguments), or you'd have an infinite loop caused by the recursion of mob/Login() (since /mob/player inherits /mob/Login(), and Login() is called whenever a client "logs into" a mob).
About not knowing about instantiating: Happens when you learn a bit too fast. I'll remember that one for sure.

And the locate really works okay, you can try it out ;) Thanks man!
In response to Kayren
Kayren wrote:
And the locate really works okay, you can try it out ;) Thanks man!
Just tried it. It compiles, which is kinda sad on DM's part...
However, it seems to just return null. It doesn't seem to assume a default z argument. Luckily, the default behavior of Login() is to place the mob on the map somewhere, so you might not have noticed that it isn't actually doing anything.

Also, when instantiating atoms, the first argument to the new() instruction (which calls New() with the same arguments afterwards) is used as the atom's initial loc:
// Instead of this:
var/mob/player/p = new
p.loc = blah

// You should be doing this:
var/mob/player/p = new(blah)
Thanks man, I'll remember.