Algorithm Help

0 views
Skip to first unread message

basil60

unread,
Oct 30, 2009, 3:40:55 AM10/30/09
to MOO Talk
I'll preface this with I'm a noob at MOO programming, but you'll soon
work that out.
I've done the Pepsi Tutorial by Mark Horan.

What I'd like to do is to create a vending machine - that can select
from pepsi,coke,fanta etc. Preferably with each being drinkable.
I'd like there to be a limit on the items in the vending machine ie 10
of each, and when 10 have been taken, it would indicate none are left.
I'd like it to refill after a period of time.
I don't want you to do this for me...can I just get some guidance on:

a)is it possible for a noob?
b)can it be a generic vending machine and alter it to hold
confectionary?

Look forward to hearing from you

basil

Michael Taboada

unread,
Oct 30, 2009, 4:19:10 PM10/30/09
to MOO-...@googlegroups.com
A:
Yes, I'd say it is possible for a newb, maybe with a little guidance.
b:
I would say it would be possible.
First, what I would do to get it to be generic and hold different types of
things, heck, they could be anything, beach balls, drinks, foods, whatever
you like, is to make a property on the vending machine that looks something
like this:
{{"<item 1 name>", #<parent number>, <amount to hold>}, {"<item 2 name>",
#<item 2 parent>, <amount to hold>}, ...}
Then when selecting what to make, you could do:
thing = $recycler:_create(this.stuff_in[<number of option>][2]);
thing.name = this.stuff_in[<number of option>][1];
Clarification:
The list is simply a list of lists, each list being the name of the object
to be created, the number of the parent of the drink/food/whatever, and then
the amount to hold in the machine.
In this way, you could make a vending machine that gives out bracelets, or
books, or whatever the heck you want, as long as you have a parent for it.
Also, if you wanted each thing to have a set price, you could do a fourth
item in each nested list that would be a number like 200 that represents the
amount to take away from the player when they buy it, if you have got that
far in the coding to make money, that is.
Hope this helps,

-Michael

AI5HF

Http://ai5hf.mtgames.org/
http://moo.mtgames.org/
"A world that contained something as amazing as that bumblebee was a world
in which he wanted to live." -- Christopher Paolini, Brisingr
"The songs of the dead are the lamentations of the living." -- Christopher
Paolini, Eldest
skype: lilmike2
msn: ai...@hotmail.com
gmail: ai5hf....@gmail.com

pc details:
Intel quad core q6700-2.66 GHz; 4 gb ddr2 duel channel ram; 500 gb
harddrive; windows xp pro.


--------------------------------------------------
From: "basil60" <prayne...@gmail.com>
Sent: Friday, October 30, 2009 2:40 AM
To: "MOO Talk" <MOO-...@googlegroups.com>
Subject: [MOO-talk] Algorithm Help
> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google Groups
> "MOO Talk" group.
> To post to this group, send email to MOO-...@googlegroups.com
> To unsubscribe from this group, send email to
> MOO-talk+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/MOO-talk?hl=en
> -~----------~----~----~----~------~----~------~--~---
>

basil60

unread,
Dec 18, 2009, 11:25:58 PM12/18/09
to MOO Talk
Hi
I'd been sitting on this till I'd learnt a little more. Because it's
been a while, let me quickly explain again what I want to do.
Create a drink machine that dispenses cans of drink.

Questions 1. I created the Pepsi from the tutorial, and made it
fertile. My Coke and Fanta now have Pepsi as theire parent (#211). How
do I change their names - for example in Pepsi - it will say something
like "You need to be holding the pepsi to drink it!". Obviously that
needs to change in each of the children. How do I do that?

Question 2. I read about $recycler:_create using help, but couldn't
find it in the manual. Here's what I came up with - not complete just
trying to make sure first bit is right

The errors I get are -
#63:_recreate, line 5: Type mismatch which
is actually 5: val = this:_recreate(@args);
... called from #63:_create, line 5
which is actually 4. thing = $recycler:_create(this.stuff_in[n][1]);
... called from #253:select, line 4
(End of traceback)

I don't have much of a clue about the syntax of the recycler - which
is probably obvious.

@create $thing named drink_machine:drink_machine
@prop #253."stuff_in" {} rc
;;#253.("stuff_in") = {"{{\"Pepsi\",#211,10}", "{\"Coke\",#251,10}",
"{\"Fanta\",#252,10}}"}
;;#253.("aliases") = {"drink_machine"}


@verb #253:"select" this none none rxd
1: player:tell("For an icy cold drink - select from the following.
Press 1 for Pepsi, 2 for Coke or 3 for Fanta");
2: n = toint($command_utils:read("your selection"));
3: if (n = 1)
4: thing = $recycler:_create(this.stuff_in[n][1]);
5: player:tell("You've selected a Pepsi");
6: else
7: if (n = 2)
8: thing = $recycler:_create(this.stuff_in[n][2]);
9: player:tell("You've selected a Coke");
10: else
11: if (n = 3)
12: thing = $recycler:_create(this.stuff_in[n][3]);
13: player:tell("You've selected a Fanta");
14: endif
15: endif
16: endif
17: "Last modified Sat Dec 19 13:55:52 2009 EST by woger (#197).";

> Http://ai5hf.mtgames.org/http://moo.mtgames.org/


> "A world that contained something as amazing as that bumblebee was a world
> in which he wanted to live." -- Christopher Paolini, Brisingr
> "The songs of the dead are the lamentations of the living." -- Christopher
> Paolini, Eldest
> skype: lilmike2
> msn: ai...@hotmail.com

> gmail: ai5hf.lilm...@gmail.com


>
> pc details:
> Intel quad core q6700-2.66 GHz; 4 gb ddr2 duel channel ram; 500 gb
> harddrive; windows xp pro.
>
> --------------------------------------------------

> From: "basil60" <prayner.ba...@gmail.com>

Michael Taboada

unread,
Dec 18, 2009, 11:53:50 PM12/18/09
to moo-...@googlegroups.com
Question 2:
You're trying to create something from parent "pepsi", which doesn't exist.
I believe you meant thing = $recycler:_create(this.stuff_in[toint(n)][2]);
That is because the parent is held in [2], not 1.
You might want to make
this.stuff_in[toint(n)][3]=this.stuff_in[toint(n)][3]-1;
To make it not allow more than are in the machine to be created.

That would mean you'd need to put an if: if(this.stuff_in[toint(n)][3] <= 0)
player:tell("There's not enough of that!");
Question 1:
What I would do is make it say player:tell("You need to be holding ",
this.name, " to drink it!");
Instead of player:tell("You need to be holding the pepsi to drink it!");
This way you can make it extendable to any type of drink, just name it
something like milk and it will say "You need to be holding the milk to
drink it!
The corrected code:


1: player:tell("For an icy cold drink - select from the following. Press 1
for Pepsi, 2 for Coke or 3 for Fanta");
2: n = toint($command_utils:read("your selection"));

"Changed = to ==, so it isn't always 1";
3: if (n == 1)
4: thing = $recycler:_create(this.stuff_in[n][2]);
"Now we must set the aliases and name";
thing.name=this.stuff_in[n][1];
thing.aliases={thing.name};


5: player:tell("You've selected a Pepsi");

"Now move it to the player";
thing:moveto(player);
"changed else if to elseif, to save space, also changed = to ==";
6: elseif(n == 2)


8: thing = $recycler:_create(this.stuff_in[n][2]);

"set all the props";
thing.name=this.stuff_in[n][1];
thing.aliases={thing.name};


9: player:tell("You've selected a Coke");

"Move to player";
thing:moveto(player);
"another elseif";
10: elseif(n == 3)
12: thing = $recycler:_create(this.stuff_in[n][2]);
thing.name=this.stuff_in[n][1];
thing.aliases={thing.name};


13: player:tell("You've selected a Fanta");

thing:moveto(player);
"Check if he entered invalid input";
else
player:tell("Sorry, that's not a choice!");
14: endif
"removed all the endifs, as they're no longer needed";
"Note that I'm setting the aliases to the names, because that's the only way
I can think of to make them accessible with aliases.";
"Ideally, you would have a :alias verb on #1, but you don't, so yeah.";
"Also note that this.stuff_in[n] takes care of which drink, then you just
have to do [2] for the parent, or [1] for the name";
"You might want to add code for checking if there are more drinks, like
this:";
"if(this.stuff_in[n][3] <= 0)";
"player:tell("There are none of that drink available");";
"return;";
"Note that return; makes the verb end, even if it is not done, thereby not
letting it create a drink";
"gosh, another note: You might do one thing like player:tell("You have
selected a ", thing.name, "."); to make it more flexible";
Hope that helped,
-Michael

AI5HF

Http://ai5hf.mtgames.org/


http://moo.mtgames.org/
"A world that contained something as amazing as that bumblebee was a world
in which he wanted to live." -- Christopher Paolini, Brisingr
"The songs of the dead are the lamentations of the living." -- Christopher
Paolini, Eldest
skype: lilmike2
msn: ai...@hotmail.com

gmail: ai5hf....@gmail.com

pc details:
Intel quad core q6700-2.66 GHz; 4 gb ddr2 duel channel ram; 500 gb
harddrive; windows xp pro.


--------------------------------------------------
From: "basil60" <prayne...@gmail.com>
Sent: Friday, December 18, 2009 10:25 PM
To: "MOO Talk" <MOO-...@googlegroups.com>
Subject: [MOO-talk] Re: Algorithm Help

> Hi

> --


>
> You received this message because you are subscribed to the Google Groups
> "MOO Talk" group.

> To post to this group, send email to MOO-...@googlegroups.com.


> To unsubscribe from this group, send email to

> MOO-talk+u...@googlegroups.com.


> For more options, visit this group at

> http://groups.google.com/group/MOO-talk?hl=en.
>
>

Paul Rayner

unread,
Dec 19, 2009, 4:39:12 AM12/19/09
to moo-...@googlegroups.com
Helped? Awesome post.

A couple of questions if I may?

When I run select drink_machine, and then choose 1,2 or 3 - it produces a traceback.


#63:_recreate, line 5:  Type mismatch
... called from #63:_create, line 5
... called from #253:select, line 4
(End of traceback)

I did a bit of playing around. My list looks like this -
{" {{\"Pepsi\",#211,10}, {\"Coke\",#251,10}\",", "{\"Fanta\",#252,10}}"}

I entered it this way -
{
{"Pepsi",#211,10}
}

To test it, I created a new verb:
@verb #253:"test" this none none rxd
@program #253:test
player:tell(this.stuff_in[2][1]);
when I run this verb, it returns

{
when I expected a "Coke"

I've never done a list of lists before, but that looks like where at least part of the error may be.

Also, in your reply, you said - "Ideally, you would have a :alias verb on #1, but you don't, so yeah.";

What do you mean an alias verb? I haven't bothered much with descriptions, aliases etc while my code doesn't work. I write some pseudo code, code it, cock it up, consult this forum, and then after it works, add the text bits that may it all sound and look good.

Thanks so much for your detailed reply.

Michael Taboada

unread,
Dec 19, 2009, 12:41:03 PM12/19/09
to moo-...@googlegroups.com
Well, some moos have a verb that is called by <number of object>:alias().
This verb sets the aliases based on the name, so if you had something called a big black truck, that aliases would be {"big black truck", "black truck", "truck"} so you could access it with any part of the name.
I will go ahead and explain how lists within lists work:
When you have a list, the [<number>] tells it which part of the list to look at.
So in the easiest case, you would have a list like {1, 2, 3, 4}
That way, list[1] would be 1, because it is the first in the list, [2] would be 2, and so on.
If you have lists within lists, you simply stack the []s.
That means, if you had {{1, 2, 3, 4}, {5, 6, 7, 8}} then list[1][1] would be 1, because it looks at the first thing in the big list, sees that it's a list, and then looks at the first thing in that listand it is 1.
That would go the same for lists within lists within lists, just remember that the first [] looks at the outside list, then the next looks at the next in, and so on.
something I saw that looked funky with your list was that you had it in quotes.
It needs to be just like that, {{"pepsi", <obj number>, 10}, {"coke", <obj number>, 10}, {"another drink", <obj number>, 10}}
You need no quotes, because then it thinks it is a string.
And that is why you are getting {, because the first element of the list is a string, and the first element of the string is {.
That is to say that [] works the same on strings as it does on lists:
"abcde"[1] would be a, because it is the first letter in the string, [2] would be b, and so on.
In conclusion, {"{something, something else, something more}"} would not be right, because the only thing in the list is a string, but {{something, something else, something more}} would be right, because the inside element is a list.
Hope this helps,
 
-Michael
 
AI5HF
 
Http://ai5hf.mtgames.org/
http://moo.mtgames.org/
"A world that contained something as amazing as that bumblebee was a world in which he wanted to live." -- Christopher Paolini, Brisingr
"The songs of the dead are the lamentations of the living." -- Christopher Paolini, Eldest
skype: lilmike2
msn: ai...@hotmail.com
gmail: ai5hf....@gmail.com
 
pc details:
Intel quad core q6700-2.66 GHz; 4 gb ddr2 duel channel ram; 500 gb harddrive; windows xp pro.

Luke-Jr

unread,
Dec 19, 2009, 1:51:19 PM12/19/09
to moo-...@googlegroups.com
On Saturday 19 December 2009 03:39:12 am Paul Rayner wrote:
> I did a bit of playing around. My list looks like this -
> {" {{\"Pepsi\",#211,10}, {\"Coke\",#251,10}\",", "{\"Fanta\",#252,10}}"}
>
> I entered it this way -
> {
> {"Pepsi",#211,10}
> }

Are you trying to use @edit for your property? That will only work for a list
of strings. For this, you will need to use eval to modify the property.

eval #253.stuff_in = {}
eval #253.stuff_in = {@#253.stuff_in, {"Pepsi", #211, 10}}
eval #253.stuff_in = {@#253.stuff_in, {"Coke", #251, 10}}
eval #253.stuff_in = {@#253.stuff_in, {"Fanta", #252, 10}}

Michael Taboada

unread,
Dec 19, 2009, 2:05:44 PM12/19/09
to moo-...@googlegroups.com
Ah yes, it does look like you're trying to use @edit.
In that case, that only works with strings, and that means when you put in
the list, it comes out as a string.
As Luke said, ;<theobjectnumber>.stuff_in={{"pepsi", <number>, 10}, {more},
{more}}; should work.
Good catch.

-Michael

AI5HF

Http://ai5hf.mtgames.org/
http://moo.mtgames.org/
"A world that contained something as amazing as that bumblebee was a world
in which he wanted to live." -- Christopher Paolini, Brisingr
"The songs of the dead are the lamentations of the living." -- Christopher
Paolini, Eldest
skype: lilmike2
msn: ai...@hotmail.com
gmail: ai5hf....@gmail.com

pc details:
Intel quad core q6700-2.66 GHz; 4 gb ddr2 duel channel ram; 500 gb
harddrive; windows xp pro.


--------------------------------------------------
From: "Luke-Jr" <lu...@dashjr.org>
Sent: Saturday, December 19, 2009 12:51 PM


To: <moo-...@googlegroups.com>
Subject: Re: [MOO-talk] Re: Algorithm Help

> On Saturday 19 December 2009 03:39:12 am Paul Rayner wrote:

Paul Rayner

unread,
Dec 19, 2009, 5:46:21 PM12/19/09
to moo-...@googlegroups.com
Thanks guys ..... I was actually using the editor in enCore. I think I might have to switch over to another editor. But that's another story.
There is potential for my MOO to become untidy, as people drop empty cans around the place.

Is the best way to deal with that to say that once the can is empty and dropped, that it automatically gets recycled?

Basil

Matthew Walker

unread,
Dec 19, 2009, 5:48:52 PM12/19/09
to moo-...@googlegroups.com
Have a recycling station that pays a small amount per can that they recycle. ;)

>> > MOO-talk+u...@googlegroups.com<MOO-talk%2Bunsu...@googlegroups.com>


>> .
>> > For more options, visit this group at
>> > http://groups.google.com/group/MOO-talk?hl=en.
>> >
>> >
>>
>> --
>>
>> You received this message because you are subscribed to the Google Groups
>> "MOO Talk" group.
>> To post to this group, send email to MOO-...@googlegroups.com.
>> To unsubscribe from this group, send email to

>> MOO-talk+u...@googlegroups.com<MOO-talk%2Bunsu...@googlegroups.com>


>> .
>> For more options, visit this group at
>> http://groups.google.com/group/MOO-talk?hl=en.
>>
>>
>>
>
> --
>
> You received this message because you are subscribed to the Google Groups "MOO Talk"
> group.
> To post to this group, send email to MOO-...@googlegroups.com.
> To unsubscribe from this group, send email to MOO-talk+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/MOO-talk?hl=en.
>
>
>


--
Matthew Walker
Kydance Hosting & Consulting, Inc. - http://www.kydance.net/
PHP, Perl, and Web Development - Linux Server Administration

Paul Rayner

unread,
Dec 19, 2009, 10:52:23 PM12/19/09
to moo-...@googlegroups.com
I must have made a pretty basic mistake here. OK -I did!!!

On my recycle_station (alias bin) in created a verb drop.
@create $thing named recycle_station:recycle_station,bin

;;#258.("aliases") = {"recycle_station", "bin"}


@verb #258:"drop" any in any rxd
@program #258:drop
recycle(dobj);
player:tell("Thanks for keeping the MOO tidy!");

So I figured when I used

drop Coke in Bin - it would only drop the Coke I had on me, which would always have a different number being created dynamically.

The bottom line it's dropped my Generic Can #211 (Pepsi).

Was I all that far off really?

Basil

Luke-Jr

unread,
Dec 19, 2009, 11:48:03 PM12/19/09
to moo-...@googlegroups.com
On Saturday 19 December 2009 09:52:23 pm Paul Rayner wrote:
> @program #258:drop
> recycle(dobj);
> player:tell("Thanks for keeping the MOO tidy!");

Oh... my...

drop me in bin

But don't do that.

Matthew Walker

unread,
Dec 19, 2009, 11:51:27 PM12/19/09
to moo-...@googlegroups.com

Wow. Yeah. You'd want to check that dobj was a descendant of your generic can. Which is
now recycled. Ouch. You had the code backed up, right?

Stephen Gigante

unread,
Dec 20, 2009, 5:54:34 PM12/20/09
to moo-...@googlegroups.com
About your test verb,

When you're trying to debug something with lists, rather than player:tell(list); or player:tell(list[1]); player:tell(list[2]); etc, you should use toliteral()


@verb #253:"test" this none none rxd
@program #253:test
player:tell(toliteral(this.stuff_in[2]));
.

That way, it will show you the list properly, rather than giving {list}, or needing to enumerate each component.

Stephen


--

Paul Rayner

unread,
Dec 20, 2009, 6:41:57 PM12/20/09
to moo-...@googlegroups.com
Hi

rebuilt my generic can after recycling it.
Moved that generic can to #-1

When I use "select drink_machine" and choose option 2 or 3, I get an error -
#253:select, line 12:  Type mismatch
(End of traceback)
or line 19 - depending which option is selected.

Any ideas why that would happen? Pepsi - option no 1 works OK. It was working OK before! And my list has tested OK and is working.

A second question - I'm getting the odd "ambiguos name" message - if I get and drink and Pepsi, and don't bin it. Can I relatively easily avoid that - other than by using obj numbers?

Basil


 1: player:tell("For an icy cold drink - select from the following. Press 1 for Pepsi, 2 for Coke or 3 for Fanta");
 2: n = toint($command_utils:read("your selection"));
 3: if (n == 1)
 4:   thing = $recycler:_create(this.stuff_in[n][2]);
 5:   thing.name = this.stuff_in[n][1];
 6:   thing.aliases = {thing.name};
 7:   player:tell("You've selected a Pepsi");
 8:   thing:moveto(player);
 9: elseif (n == 2)
10:   thing = $recycler:_create(this.stuff_in[n][2]);
11:   "set all the props";
12:   thing.name = this.stuff_in[n][1];
13:   thing.aliases = {thing.name};
14:   player:tell("You've selected a Coke");
15:   "move to player";
16:   thing:moveto(player);
17: elseif (n == 3)
18:   thing = $recycler:_create(this.stuff_in[n][2]);
19:   thing.name = this.stuff_in[n][1];
20:   thing.aliases = {thing.name};
21:   player:tell("You've selected a Fanta");
22:   thing:moveto(player);
23:   "check to see if he entered valid input";
24: else
25:   player:tell("Sorry, that's not a choice!");
26: endif
27: "Last modified Mon Dec 21 08:54:46 2009 EST by woger (#197).";

On Sun, Dec 20, 2009 at 5:05 AM, Michael Taboada <ai5hf....@gmail.com> wrote:

Michael Taboada

unread,
Dec 20, 2009, 7:05:10 PM12/20/09
to moo-...@googlegroups.com
Just make sure that [n][1] is a string, I.E. "pepsi"
 
-Michael
 
AI5HF
 
Http://ai5hf.mtgames.org/
http://moo.mtgames.org/
"A world that contained something as amazing as that bumblebee was a world in which he wanted to live." -- Christopher Paolini, Brisingr
"The songs of the dead are the lamentations of the living." -- Christopher Paolini, Eldest
skype: lilmike2
msn: ai...@hotmail.com
gmail: ai5hf....@gmail.com
 
pc details:
Intel quad core q6700-2.66 GHz; 4 gb ddr2 duel channel ram; 500 gb harddrive; windows xp pro.
Reply all
Reply to author
Forward
0 new messages