ID:149728
 
I my life rpg i have it so people can get jobs and thay get payed tho ikeep getting this runtime error

runtime error: Cannot read null.police.
proc name: Pay (/proc/Pay)
usr: null
src: null
call stack:
Pay()
: New()
: New()

heres my code

world/New()
sleep(5000)

Pay()




proc/Pay()

if(usr:police>=1)
sleep(5000)
usr << "PAY ROLL"
usr.money += 300 //
return
if(usr:thief>=1)

sleep(5000)
usr.money += 50 // minuses the amount from the money on you
return
if(usr:lawer>=1)

sleep(5000)
usr.money += 700 // minuses the amount from the money on you
return

spawn(5) Pay()
Rollerc wrote:
I my life rpg i have it so people can get jobs and thay get payed tho ikeep getting this runtime error

runtime error: Cannot read null.police.
proc name: Pay (/proc/Pay)
usr: null
src: null
call stack:
Pay()
: New()
: New()

You're using usr:var in a proc that's called during world.New(), when usr doesn't even exist yet.

In most cases you should avoid using usr and use src instead anyway; it's usually more appropriate and avoids bugs. usr belongs only in verbs. Pay() is not a verb; it's something that's happening when your world starts up.

In your code, it's unclear how you would replace usr with anything, let alone src, because you seem to be calling the proc in a bizarre place. What looks like it was intended to be a proc specific to a mob and called in-game is put into a global proc instead. Is it supposed to be looping through every player in the world (and if so, why is it being called at startup)?

When the world starts, there are no players, and no mobs except what you've put on the map. In Pay(), you're telling DS that something exists that doesn't yet.

Rollerc: Okay, the world was just created. There's this guy out there, and I want to pay him.
DS: Um... where did the guy come from?
Rollerc: He's usr.
DS: But the world was just created. It's empty. Nobody's logged in yet. There is no usr yet.

See what I mean?
This is probably how you want to do it instead:

Rollerc: We've been running for a while now, so it's time to pay everyone with Pay().
DS: Okey dokey.
Rollerc: Loop through every mob in the world, and do such-and-such for each one.
DS: Done.

It looks like you're calling code that belongs in a loop, and should be called at a different time during the game.

Lummox JR
In response to Lummox JR
thanks i never looked at it like that no wounder i get alot of errors from that
tho i get this error mobs.dm:27:error:src.money:undefined var
In response to Rollerc
i still keep gtting ths error mobs.dm:27:error:src.money:undefined var

i put urs for the money and that dont work nd i have a var for money
In response to Rollerc
Rollerc wrote:
i still keep gtting ths error mobs.dm:27:error:src.money:undefined var

i put urs for the money and that dont work nd i have a var for money

usr is completely inappropriate to this situation, so don't use it. Don't even think about using it. usr is for verbs, verbs only. Once you get more comfortable with using it in that sense, then it's easier to know when and how to use it in other procs.

The reason src isn't working for you right now, and thus src.money is not giving you access to a mob's money var, is because Pay() is still a global proc. From what I can tell of your intent, Pay() should be a proc belonging to a mob.

Lummox JR
In response to Lummox JR
is thare a better way todo it??