ID:138480
 
Hello all!

I hope some kind person could help me out. I'm a newbie to BYOND and programming for that matter.

I'm having a terrible time getting things(mob,obj etc) to really interact with each other. Let me give an example of something I would like to do and perhaps someone could post a code snippet that shows how to do it. I'm sure this would go a long way in helping me understand.

I'll use a simple example like one mob being able to go up and kick another mob. I can get it to SAY that a mob kicked another mob, but how do I get from having it say it happens to having it really do something to the other mob, ie. reduce it's health?

I'm sure there is probably some easy concept that I am missing, so if someone could explain it I would appreciate it.

Thanks,

Taipan

I'll use a simple example like one mob being able to go up and kick another mob. I can get it to SAY that a mob kicked another mob, but how do I get from having it say it happens to having it really do something to the other mob, ie. reduce it's health?

Easy as pie! From your example I guess you've been reading the Guide in the DM InfoCenter... good way to start. It's a little outdated, but you'll get a great feel for the language, and there's a much bigger edition coming soon.


mob
var/health = 100 // Starting value for health

verb/kick(mob/M as mob in view(1))
var/damage = rand(1, 10)
M.health -= damage
if(M.health > 0)
world << "[usr] kicks [M] for [damage] points of damage!"
else
world << "[usr] has killed [M]!"
del M



You can get a lot more sophisticated than this, of course, like playing a "kick" sound or showing a little movie or moving M to wander in the underworld for a while... but that will come with time.

Note that in the arguments to "kick," I changed the Guide example so it says "mob/M" instead if simply "M". This tells the compiler that we're pretty sure M will be a mob. That's important, because otherwise, the compiler has no idea what M will be, and it will tell us "M.health" is meaningless since only mobs have a health value!

And to make it even more confusing, the "mob/M" has very little to do with the "as mob" on the same line. "mob/M" tells the compiler what the target will be; "as mob" tells the client (Dream Seeker) what the target is allowed to be. In other words, "as mob" means the player will only be allowed to enter a mob's name as the target.

If you're new to programming, this probably sounds incredibly wacky. Don't despair; in no time it'll all be old hat to you. There's a lot of info on this site; check out the Code & Demos section (just under the DM InfoCenter link), especially the Tutorials. Also, just browsing through the past messages in the forums can give you some neat tips and ideas.

Welcome to BYOND!
In response to Guy T.
Thanks a lot. This clarified a lot of things for me. I'm beginning to think I have a chance of making a game. :)



On 7/20/00 5:05 pm Guy T. wrote:
I'll use a simple example like one mob being able to go up and kick another mob. I can get it to SAY that a mob kicked another mob, but how do I get from having it say it happens to having it really do something to the other mob, ie. reduce it's health?

Easy as pie! From your example I guess you've been reading the Guide in the DM InfoCenter... good way to start. It's a little outdated, but you'll get a great feel for the language, and there's a much bigger edition coming soon.


mob
var/health = 100 // Starting value for health

verb/kick(mob/M as mob in view(1))
var/damage = rand(1, 10)
M.health -= damage
if(M.health > 0)
world << "[usr] kicks [M] for [damage] points of damage!"
else
world << "[usr] has killed [M]!"
del M



You can get a lot more sophisticated than this, of course, like playing a "kick" sound or showing a little movie or moving M to wander in the underworld for a while... but that will come with time.

Note that in the arguments to "kick," I changed the Guide example so it says "mob/M" instead if simply "M". This tells the compiler that we're pretty sure M will be a mob. That's important, because otherwise, the compiler has no idea what M will be, and it will tell us "M.health" is meaningless since only mobs have a health value!

And to make it even more confusing, the "mob/M" has very little to do with the "as mob" on the same line. "mob/M" tells the compiler what the target will be; "as mob" tells the client (Dream Seeker) what the target is allowed to be. In other words, "as mob" means the player will only be allowed to enter a mob's name as the target.

If you're new to programming, this probably sounds incredibly wacky. Don't despair; in no time it'll all be old hat to you. There's a lot of info on this site; check out the Code & Demos section (just under the DM InfoCenter link), especially the Tutorials. Also, just browsing through the past messages in the forums can give you some neat tips and ideas.

Welcome to BYOND!