the variable to hold a players skills is
mob
var
skills[0]
So for the mob I wrote
mob/Login()
var/tmp/skill/trading/TSkill = new /skill/trading()
TSkill.rank = 5
src.skills["Trade"] = TSkill
return ..()
mob/Bump(O)
if (istype(O,/mob))
var/tmp/mob/M = O
var/tmp/skill/trading/TradeSkill = usr.skills["Trade"]
TradeSkill.TradeGoods(usr,M)
return ..()
and for the datum I wrote
skill
var
label
rank
exp
trading
label = "Trade"
proc
TradeGoods(U,T)
var/tmp/mob/User = U
var/tmp/mob/Target = T
var/tmp/skill/trading/UserTrade = User.skills["Trade"]
var/tmp/skill/trading/TargetTrade = Target.skills["Trade"]
var/tmp/UserRoll = rand(1,20) + UserTrade.rank
var/tmp/TargetRoll = rand(1,20) + TargetTrade.rank
UserTrade.exp++
User << "Trade Successful [UserRoll] - [TargetRoll] total exp [UserTrade.exp]"
User << "Your rank is [UserTrade.rank]"
The problem is that this returns runtime error: Cannot read null.rank
Which is crazy because if I exclude the rolls and leave
User << "Your rank is [UserTrade.rank]"
it tells me Your rank is 5 !!! So it is getting the rank successfully if I am sending it in text but the skill grab turns up null if I try to use it as a number?
My problem with understanding why a datum is useful is due to getting errors like this anytime I have tried to experiment with one. This error doesn't make sense to me.
2. tmp is useless for local variables. It marks an instance variable as one that should not be saved automatically by datum.Write(savefile)'s default action.
3. You can define proc parameters with a type like any other variable, so casting U to mob/User in TradeGoods is unnecessary (but casting O to M in Bump is necessary).
4. It's possible that TargetTrade is null, not UserTrade, causing the runtime error in the definition of TargetRoll. (If you enable debugging in your project's Build Preferences, the error will point to the file and line number that the error is on, just like compiler errors.) For example, since the trade skill appears to only be given to players in Login(), NPCs wouldn't have it.
5. UserTrade is unnecessary; it's the same as src.