I have spent the last 3 or 4 days reading every tutorial on the web site I can fine. I also have a copy of the blue book and I have been reading over that. I am attempting to write some test code to play around with the byond features and all I get is errors. I have written some code that creates 2 mobs and sets some variables for each. Then I have a Attack verb that allows the player to attack.
Here is my code:
world
name = "Test World"
mob = /mob/human
turf = /turf/grass
mob
human
icon = 'human.dmi'
var
hp = 25
defense = 10
strength = 25
condition = "Fine"
exp
verb
Train()
strength +=2
mob
bug
icon = 'bug.dmi'
var
hp = 4
defense = 3
strength = 4
verb
Attack(mob/M as mob in oview(1))
var/damage = rand(4,6)
var/expgain = rand(2,6)
M.hp -= damage
usr.exp += expgain
view() << "[usr] attacks [M] for [damage] HP!"
usr << "You gain [expgain] experience"
turf
grass
icon = 'grass.dmi'
The problem comes in with the attack verb
I am attempting to generate 2 random variables for damage and experience then I subtract damage from M.hp which should take away the value of damage from the hitpoints of the mod the player attacks. Then it should add the value of expgain to the usrs exp variable.
When I complie this code I get 2 errors
testworld.dm:24:error:M.hp:undefined var
testworld.dm:25:error:usr.exp:undefined var
What am I missing? I have read through the chapter on variables in the blue book 2 times and I can't understand why I am getting this error.
There must be some Key concept I am missing.
ID:178958
Mar 13 2002, 12:45 pm
|
|
In response to Canar
|
|
You can save space when defining vars by doing something like this:
mob |
i didnt see any variables on that so add them like this
var HP = 29034 MaxHP = 890349349 |
You defined variables for mob/human and mob/bug (the child types), but not for mob (the parent type). M and usr are mobs.
Maybe you could use the : operator. Maybe you could check the type of M or usr and then create the proper kind of var to use. However, the usual practice is to just give the parent type the shared variables. (Give mob what mob/human and mob/bug have in common.) |
Ok, Thank you everyone..
Let me just make sure I understand basically you can create a parent mob and then all the children will have the variables you assign to that mob. The only thing with that is what if I have 30 or so mobs and I want them all to have diffrent stats, hp, exp, etc. In my code above I put /mod/var/hp /mod/var/exp Then I had to take out the hp and exp for both human and bug mod otherwise I get duplicate definition errors. So how do you over ride the parent variables for individule mods? |
In response to Shwn
|
|
the only way I know to do it is at login(its probably not the right way but its how I do it). here is an example...
mob/var/hp = 50 again this is probably not the right way to do it but it will work. |
In response to Canar
|
|
Almost, but Login() is never called for NPCs.
mob |
In response to Nadrew
|
|
yea but my post just talked about the player I didnt know about the NPC
|
In response to Nadrew
|
|
Excellent, Thank you very much for your help
|
and then you can still leave what you have because it will simply edit these variables. that should work.