ID:180811
 
how do I make it possible to use the verb Eat like this:

I want the verb eat to be specified, directly under obj.
The verb should print "You eat [src]" or something like that, then it should call a proc on the object digested to see what happens to the object and the mob whos eating.

how do I do this?

or do I have to do it some other way?
On 2/13/01 11:48 am Kaidorin wrote:
how do I make it possible to use the verb Eat like this:

I want the verb eat to be specified, directly under obj.
The verb should print "You eat [src]" or something like that, then it should call a proc on the object digested to see what happens to the object and the mob whos eating.

how do I do this?

or do I have to do it some other way?

Now you know how to do this already!

Go back to the equip verb discussion, and you'll see that all the info you need is there.
In response to Deadron
food
verb
eat()
usr << "You eat [src]"
src.eating
bread
loaf
name = "loaf of bread"
icon = 'loafofbread.dmi'
desc = "a loaf of bread"
var
size = 4
proc
eating()
var/size = size - 1

bread
name = "piece of bread"
icon = 'pieceofbread.dmi'
desc = "a piece of bread"

this is my code, when i try to compile it gives me these warnings:
src is an unused label
eating is an unused label

what should I do?

I am a total newbie.
In response to Kaidorin
src.eating

Since eating is a proc call, put parentheses after it:

src.eating()

proc
eating()
var/size = size - 1

You don't need "var/" before size here. Also, the line needs to be indented one more tab.

Offhand, those are the only two things I noticed. Give it a try and we'll see!
In response to Guy T.
here is the updated code:
food
verb
eat()
usr << "You eat [src]"
src.eating()
bread
loaf
name = "loaf of bread"
icon = 'loafofbread.dmi'
desc = "a loaf of bread"
var
size = 4
proc
eating()
size =size-1

now I recieve the following errors:
code\objects.dm:26:error:size :duplicate definition
code\objects.dm:23:error:size :previous definition
code\objects.dm:26:error:size:invalid variable
code\objects.dm:26:error:= :expected a constant expression
code\objects.dm:16:error:src.eating:bad proc

what is wrong?
In response to Kaidorin
bread
loaf
name = "loaf of bread"
icon = 'loafofbread.dmi'
desc = "a loaf of bread"
var
size = 4
proc
eating()
size =size-1

Looks like it's still an indentation problem. Try this...

bread
loaf
name = "loaf of bread"
icon = 'loafofbread.dmi'
desc = "a loaf of bread"
var
size = 4
proc
eating()
size = size-1
In response to Guy T.
tried it and now I only get one error:

code\objects.dm:16:error:src.eating:bad proc

this is the code reffered to:

food
verb
eat()
usr << "You eat [src]"
src.eating()

i can't see anything wrong in it.

In response to Kaidorin
On 2/13/01 12:46 pm Kaidorin wrote:
tried it and now I only get one error:

code\objects.dm:16:error:src.eating:bad proc

this is the code reffered to:

food
verb
eat()
usr << "You eat [src]"
src.eating()

i can't see anything wrong in it.

Oops, missed that one! The problem is that your definition of the eating() proc is defined under bread. You need to move it out so that it's under food. Just move the whole proc to the left (select the lines of the proc and type SHIFT and TAB together to move the whole block at once). It should line up so that eat's 'verb' and eating's 'proc' are on the same level of indentation.
In response to Guy T.
how I am supposed to include different actions depending on what is eaten?

it seems to me like the now revised code, runs the same proc nomatter what is eaten, correct?

if so then I need help on defining the different actions that should take place for the different types of food.
In response to Kaidorin
how I am supposed to include different actions depending on what is eaten?

One way is: add a line to your basic "eating" proc, to call a proc called CustomEating or whatever. Like so:

food
proc/eating()
size -= 1
CustomEating()

proc/CustomEating() //this proc is just a stub that says all food types will have it... but no one is going to eat plain old "food"!

bread
CustomEating()
usr << "Mmm, starchy!"

egg
CustomEating()
usr << "That was one fine embryo!"

ostrich_egg
CustomEating()
usr << "Burp!"
In response to Guy T.
is it possible to call CustomEating directly, ie replacing the eating?
In response to Kaidorin
On 2/13/01 1:23 pm Kaidorin wrote:
is it possible to call CustomEating directly, ie replacing the eating?

I think you are asking if you can take another approach where you just have one kind of eating function that is customized for each food. Yup, that's totally doable, like so:

food
&nbsp;&nbsp;&nbsp;&nbsp;proc/eating()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;// This is where the eating function is defined for all food.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;// If some food has special requirements, it can provide it's own eating() function.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;size -= 1

&nbsp;&nbsp;&nbsp;&nbsp;bread
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;eating()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Because eating was defined as a proc under food, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// add eating() to bread without saying proc.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;u sr << "Mmm, starchy!"

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// That was our custom functionality...but we still want to call
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// the superclass (food) eating() function to let it do its thing.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// We do that by calling ..()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;..()

&nbsp;&nbsp;&nbsp;&nbsp;egg
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;eating()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;u sr << "That was one fine embryo!"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;..()

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;o strich_egg
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;&nbsp;&nbsp;eating()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;usr << "Burp!"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;..()

Now if you use this code you will see why Guy chose to use two functions...because when you eat an ostrich egg, it calls its superclass with ..(), and the superclass of the ostrich egg proc is egg.eating(), when then calls IT'S superclass, so you end up doing this:

Burp!
That was one fine embryo!
[subtract 1]

You might have only wanted to burp and subtract one instead of also doing the egg.eating() proc too. In that case, Guy's approach works better.
In response to Kaidorin
On 2/13/01 1:23 pm Kaidorin wrote:
is it possible to call CustomEating directly, ie replacing the eating?

Yep, though you'd have to add the size -= 1 to every food's CustomEating proc.

Actually, there is a better way to do it, using calls to the parent proc. How about this:

food
proc/CustomEating()
size--

bread
CustomEating()
. = ..()
usr << "Yum!"

(I was trying to hold back on the advanced techniques, but what the heck... you gotta learn it sooner or later. Besides, I think it's described in the reference somewhere. :)
In response to Kaidorin
oh, don't bother about the last question. I've figured it out.

Guy T, thanks a lot for all the help with this. I really mean it.

It is incredible actually, that all you guys (pardon the pun) have the patience to answer questions from the newbies.

I really think that is so great.


Once again, thank you Guy T!!!
In response to Guy T.
food
proc/CustomEating()
size--

bread
CustomEating()
. = ..()
usr << "Yum!"

hold back on the advanced techniques a little longer, the above went straight over my head.


To stick to the above subject, I have a question:

How do I test an objs vars in a proc?
I want the eat() to see if the obj has a size above 1 and then print "you eat a part of" else print "you eat".
In response to Kaidorin
It is incredible actually, that all you guys (pardon the pun) have the patience to answer questions from the newbies.

It's worth it when the new games come out! :)
In response to Kaidorin
On 2/13/01 1:39 pm Kaidorin wrote:
food
proc/CustomEating()
size--

bread
CustomEating()
. = ..()
usr << "Yum!"

hold back on the advanced techniques a little longer, the above went straight over my head.


To stick to the above subject, I have a question:

How do I test an objs vars in a proc?
I want the eat() to see if the obj has a size above 1 and then print "you eat a part of" else print "you eat".

proc/CustomEating()
if(size > 1)
usr << "You eat a part of [src]."

else if(size == 1)
usr << "You eat [src]."
spawn (1)
del src

size--
if(size >= 0) return 1

bread
CustomEating()
. = ..()
if(.) usr << "Mmm, bread!"

The only tricky part of this is the spawn() part. I'm telling DM to wait a tick (1/10 second) before deleting the object. Why? Because otherwise, the specific CustomEating() would not get a chance to print "Mmm!" It would stop immediately as soon as its src was killed.

Actually, there is another tricky part too... this proc will also handle the very unlikely case where the user issues another "eat" command during the time between the spawn command and the actual deletion of the object. But that's a story for another time! :)

In response to Guy T.
It's worth it when the new games come out! :)

you've got a point.

my game will take some time, the only thing in it right now is:

a guy
a piece of bread
a loaf of bread
a shirt

they all exist in a world consisting of:

grass
snow
stone wall


have you noticed that I like to make lists like those above ;)
In response to Guy T.
what exactly does the spawn(1) do?

could you plz explain this in more detail:

size--
if(size >= 0) return 1

bread
CustomEating()
. = ..()
if(.) usr << "Mmm, bread!"


thanks for all the help so far

In response to Kaidorin
what exactly does the spawn(1) do?

All activity in BYOND takes place in "ticks". There are 10 ticks per second. spawn(1) means "wait one tick before executing the following code". If you type spawn in a dm file and press F1, you should get a Reference entry with additional info.

could you plz explain this in more detail:

size--
if(size >= 0) return 1

bread
CustomEating()
. = ..()
if(.) usr << "Mmm, bread!"


thanks for all the help so far

size--
is the same as:
size = size - 1
or even:
size -= 1

(-- and -= should both be in the Refc. too.)

. is the default return value of the proc. So these two procs would behave the same:

proc/A()
. = 1

proc/B()
return 1

Both of these will return 1.

So, what I was doing in the sample was checking to see whether the parent proc (which was doing all the size checking) returned 1 (which in this case meant that the user did in fact take a bite of it). If so, I'd print "Mmm", but otherwise I'd know that the food was already all eaten, and we were just waiting for it to be deleted (and somehow the user was quick enough to sneak in one more "eat" command... it would be more useful if were were waiting a few seconds to delete the food, instead of 1/10 second).

Truth be told, I didn't write the proc real cleanly. :)
Page: 1 2