mob
characters
Sayanjin
icon='male-white.dmi'
powerlevel=100
hp=150
Click(Sayanjin)
src.race=sayanjin
switch(input("What is your gender?","Gender") in list ("Male","Female"))
if("Male")
new_mob.gender="male"
new_mob.level=1
new_mob.move=1
if("Female")
new_mob.gender="female"
spawn()NewCharacter()
Problem description:
I keep getting the runtime error: Cannot modify null.gender.and i cant seem to find my error in my code.
new_mob is null. Since you're not specifying what new_mob is within the code snippet you provided, I'm assuming you have it defined elsewhere such as under /mob. I'm assuming you have something like this:
There are two issues with that. First, I believe it to be rather poor design. If you're going to have a variable to set up a new player's mob, it should be local (defined within the proc) to whatever procs you are using and not given to every single mob (or even just the players) in your game. Once the player creates their character they no longer need to have access to the new_mob variable.
The second issue (and where your problem is coming from), is that variables containing objects (meaning atoms, custom datums, lists, etc) need to be initialized before they are accessed like you are trying to. Just by defining a variable called new_mob does not mean that you are creating a new mob to change gender and level on. And such initializations like that can only be done during runtime.
Just calling the new() proc for that should solve your problem. For example:
That will create a new /mob and store a reference of it in the new_mob variable that you can use to access it within the rest of your proc.
However, I would seriously suggest you consider on how your character creation system is working and if you can change it to be a local variable (defined AND initialized within the proc) instead.
You'd likely have to pass an argument to NewCharacter and rework some things to make it compatible with that, but overall it is a better design than the first one.