I'm guessing this is a really stupid and obvious mistake, but it's been pestering me all day
attack(mob/M)
var/damage=rand(1,strength)
view(usr)<<"[usr] attacks [M] for [damage] damage!"
M.HP-=damage
M.Death()
the errors I'm getting read:
pyro.dm:26:error:M.HP:undefined var
pyro.dm:27:error:M.Death:undefined proc
I don't understand what I'm doing wrong. this is part of the code of just one character class, so I'm guessing that has something to do with it because the "M" thing usually works when the game has only one character and an enemy, like in most of byond's normal tutorials.
I've defined HP and Death() both already, so the code works if I take out the "M" part..but if I do that, the character attacks him/herself. And I know M works, because it refers to the correct source in the message action.
Anyway, any help with this would be appreciated. I've tried everything I can think of but I'm stuck..comes with being new to DM coding, I suppose.
ID:261595
![]() Aug 14 2002, 10:51 am
|
|
chris.dm:5:error:HP :duplicate definition
pyro.dm:2:error:HP :previous definition neko.dm:5:error:HP :duplicate definition pyro.dm:7:error:HP :duplicate definition projmob.dm:30:error:HP :duplicate definition chris.dm:33:error:Death :duplicate definition pyro.dm:1:error:Death :previous definition neko.dm:32:error:Death :duplicate definition pyro.dm:31:error:Death :duplicate definition thats what I got after doing what you told me.. but, see, HP was already defined directly above this code, and Death() is done right after it. My problem is that "M" isn't declared, maybe? If this is the case, then I'm completely lost because every time I try to do that, the M.HP/Death errors still remain. Would it help at all if I posted the complete code on here? |
i think u defined mob/var/HP in each .dm file u only need to do it once same with the death proc only need to do it once
|
But then if I do that it'll say that I didn't define them in the dm files that I take them out of..and I'll just be back to a worse version of the origional problem
|
i dont really understand how ur using these it would be helpful if u post a bit of the part where the problem is
|
Pyro_ShadowStar wrote:
chris.dm:5:error:HP :duplicate definition It would obviously help, as I can only second-guess the rest of your code when trying to help you. |
Soori-99 wrote:
i dont really understand how ur using these it would be helpful if u post a bit of the part where the problem is I posted where the problem is with my first post. But I'll explain it again.. I'm trying to figure out how to use a character class system. In doing this I gave three different experimental characters different stats. What I don't understand is why I can't put even the most simplistic battle system into it. Heres what I have for one char right now, if it helps any: mob/pyro icon = 'maincharsheets.dmi' icon_state="pyro" var HP=146 max_HP=146 HP_allowed=146 MP=24 max_MP=24 strength=20 exp=0 max_exp=56 exp_give=6 level=1 gold=10 tech=0 mob/M verb say(msg as text) view(usr)<<"[usr]: [msg]" ooc(msg as text) world<<"[usr.key]: [msg]" attack(mob/M in oview(1)) var/damage=rand(1,strength) view(usr)<<"[usr] attacks [M] for [damage] damage!" M.HP-=damage M.Death() proc Death(mob,M) if(src.type==/mob/NPC) NPCDeath() else if(src.HP<=0) world<<"[src] was killed by [usr]" exp+=src.exp_give gold+=src.gold src.gold/=2 src.loc=locate(3,8,1) src.HP=max_HP src.MP=max_MP Levelup() NPCDeath(mob,M) if(src.HP<=0) view(src)<<"[src] was killed by [usr]" exp+=src.exp_give gold+=src.gold del(src) Levelup() Levelup() if(src.exp>=src.max_exp) src.level++ src.exp=0 src.max_exp*=2 src<<"You reached level [level]!" src.Statup() else ..() Statup() src.max_HP+=14 src.strength+=7 src.HP_allowed+=14 src.MP+=10 src.max_MP+=10 src.exp_give*=2 src.tech++ src.HP=src.max_HP src.MP=src.max_MP Stat() ..() statpanel("Stats") stat(usr) stat("Level:",level) stat("HP:","[HP]/[max_HP]") stat("MP:","[MP]/[max_MP]") stat("Experience:","[exp]/[max_exp]") stat("Gold",gold) Logout() del src return..() okay, and to put this as simply as I can, it won't let me make a battle system outside of each character individually or it'll say something like "this variable isn't defined that variable isnt described" blah blah. So I put the battle system in each character individually..I'm pretty sure this script should work except for these lines: attack(mob/M in oview(1)) var/damage=rand(1,strength) view(usr)<<"[usr] attacks [M] for [damage] damage!" M.HP-=damage M.Death() when I try to compile this it says M.HP and M.Death weren't defined..but I defined them right there! and it won't let me define them again outside of the mob thing or it'll give me multiple "previous definition" errors. teh..I know I'm long-winded, but this is really starting to annoy me. does anybody know a simpler way to use a class system with battle systems present? |
The fact that your attack verb was made for a /mob/pyro instead of just a /mob helps. When you were asked to define things for /mob, the duplicate definition errors came from the same things being defined in /mob and /mob/pyro.
Your attack verb takes a /mob as input. You then try to access the HP var and Death proc of that /mob. However, you declared HP and Death for /mob/pyro, not for /mob. The compilier is correct. They were not defined for M (a plain old mob). You could mess with ways to only attack things of type /mob/pyro. However, I'm not sure if that's what you want so I'm not going to offer such a solution. I suggest you move your battle code into a /mob or at least declare the HP var and Death() proc under /mob. (Built-in types are easier to access for verb input using "as".) You can always overwrite them in derived classes. |
but if I put them all under /mob, wouldnt all the characters have to have the same abilities and stats?
|
Pyro_ShadowStar wrote:
but if I put them all under /mob, wouldnt all the characters have to have the same abilities and stats? No. You can overwrite the vars and procs of a base type in a derived type. Here's an example: mob var HP = 1 proc Death() world << "mob" mob/derived // Note that these are not declared again with var and proc. // They are merely redefined. HP = 2 Death() world << "derived" mob/otherDerived // Not bothering to overwrite anything. If M is a /mob, M.HP will be 1 and M.Death() will output "mob". If M is a /mob/derived, M.Hp will be 2 and M.Death() will output "derived". This is because the value of HP and the function for Death() were overwritten. If M is a /mob/otherDerived, M.HP will be 1 and M.Death() will output "mob". This is because derived types will default to the values of their base types when they are not overwritten. |
Firstly, try changing
attack(mob/M in oview(1))
As for your first error, this can be easily fixed by defining them as variables that all mobs have. Try this:
mob/var/HP
That should solve your 'M.HP' dilemna. As for your undefined proc, the game is trying to call the Death() proc, which you haven't created. Define a proc by something like this:
mob/proc/Death()
And below it have the code that you want it to perform when it is called.
Hope that helps. :)