Hi, I had a question. This is the code of a very simple cellphone I created. Every child of generic_cellphone has a number, and this is how the code is supposed to work: Go through all the children of generic_cellphone with @foreach, and if the number attribute on any of them equals the number typed after the call command (the command syntax being call *), say connected, else say cannot find the target specified. Well, as you can see, there is one thing wrong with this algorithm. If the generic_cellphone has 100 children, then the fail message will be given 99 times. But how can I fix this? And is there something like a break command, for example, suppose we have three cellphones and the second one matches. The @foreach should stop immediately, how can I do that one? Thanks! --- Contact info: Skype: parham-d MSN: fire_lizard16 at hotmail dot com email: parham90 at GMail dot com
The method I tend to lean on for phone-number code is a bit of a cheat, using the dbref of the target object as the core of the phone-number. So if your database doesn't have anything over dbref #9999? Then trying to dial Cell Phone Object #1966 would be the in-character phone number 555-1966 (and dialing Cell Phone Object #867 would be 555-0867). Obviously, if you're up in the five digit range for dbrefs (or higher) one can change the prefix (so it's 550-1966 or whatever is required).
That way, the code just checks to see if the target dbref has the Cell Phone Parent as a parent, allowing the call to go through if it works out.
Unfortunately, this doesn't solve the initial @foreach question.
T'Then... William D. Young
Real Mail 42 Winter St, Bangor ME, 04401 E-Mail youngwill...@hotmail.com
Hi, I had a question. This is the code of a very simple cellphone I created. Every child of generic_cellphone has a number, and this is how the code is supposed to work: Go through all the children of generic_cellphone with @foreach, and if the number attribute on any of them equals the number typed after the call command (the command syntax being call *), say connected, else say cannot find the target specified. Well, as you can see, there is one thing wrong with this algorithm. If the generic_cellphone has 100 children, then the fail message will be given 99 times. But how can I fix this? And is there something like a break command, for example, suppose we have three cellphones and the second one matches. The @foreach should stop immediately, how can I do that one? Thanks! --- Contact info: Skype: parham-d MSN: fire_lizard16 at hotmail dot com email: parham90 at GMail dot com
On Thu, 2008-07-03 at 22:52 +0330, Parham wrote: > Hi, > I had a question. This is the code of a very simple cellphone I > created. Every child of generic_cellphone has a number, and this is > how the code is supposed to work: > Go through all the children of generic_cellphone with @foreach, and if > the number attribute on any of them equals the number typed after the > call command (the command syntax being call *), say connected, else > say cannot find the target specified. > Well, as you can see, there is one thing wrong with this algorithm. If > the generic_cellphone has 100 children, then the fail message will be > given 99 times. But how can I fix this? > And is there something like a break command, for example, suppose we > have three cellphones and the second one matches. The @foreach should > stop immediately, how can I do that one? > Thanks!
You could use a recursive function call instead of the @foreach.
It have been a very long time since I did any tux coding, but the principle would be to create a function that took as parameters:
1. The number you were looking for.
2. The list of child objects.
The function looks at the list of child objects. If it is empty, then the number hasn't been found, so return #-1.
Otherwise, use the first() item in the list of child objects, and match() on the number attribute. If this is found, the function returns the object id.
If it isn't found, then the function calls itself with the number you're looking for, and rest() of the list of objects.
There's some trickery needed so you don't always evaluate the rest() part, but I don't remember this in enough detail to give you an example.
Another way of tackling this problem would be to build a list of numbers from children, then do a single match on that, and use the index of the match to get back to the child object id.
Hope that helps a bit,
Mark (aka Mark Farrell @ ATS a long long time ago)
> Hi, > I had a question. This is the code of a very simple cellphone I created. Every child of generic_cellphone has a number, and this is how the code is supposed to work: > Go through all the children of generic_cellphone with @foreach, and if the number attribute on any of them equals the number typed after the call command (the command syntax being call *), say connected, else say cannot find the target specified. > Well, as you can see, there is one thing wrong with this algorithm. If the generic_cellphone has 100 children, then the fail message will be given 99 times. But how can I fix this? > And is there something like a break command, for example, suppose we have three cellphones and the second one matches. The @foreach should stop immediately, how can I do that one? > Thanks! > --- > Contact info: > Skype: parham-d > MSN: fire_lizard16 at hotmail dot com > email: parham90 at GMail dot com
>> Hi, >> I had a question. This is the code of a very simple cellphone I created. Every child of generic_cellphone has a number, and this is how the code is supposed to work: >> Go through all the children of generic_cellphone with @foreach, and if the number attribute on any of them equals the number typed after the call command (the command syntax being call *), say connected, else say cannot find the target specified. >> Well, as you can see, there is one thing wrong with this algorithm. If the generic_cellphone has 100 children, then the fail message will be given 99 times. But how can I fix this? >> And is there something like a break command, for example, suppose we have three cellphones and the second one matches. The @foreach should stop immediately, how can I do that one? >> Thanks! >> --- >> Contact info: >> Skype: parham-d >> MSN: fire_lizard16 at hotmail dot com >> email: parham90 at GMail dot com
Hello, I believe that would be what I'm looking for, but there is no help for lsearch, and I don't know the syntax, and when I put it in think, it gives back the same thing to me. I mean this: lsearch(all,ething,\[match(%0,get(##/phonenumber))\]) And this is the code I have put, which does nothing: @va generic_cellphone=$call *:@dolist [children(num(generic_cellphone))]=ifelse(lsearch(all,ething,\[match(%0,get (##/number))\]),say works,say doesn't work) Thanks. --- Contact info: Skype: parham-d MSN: fire_lizard16 at hotmail dot com email: parham90 at GMail dot com
----- Original Message ----- From: "A Character" <a_charac...@hotmail.com> To: <tinymux@googlegroups.com> Sent: Friday, July 04, 2008 12:26 AM Subject: [TinyMUX] Re: @Foreach Question
Apparently it stripped out something. lsearch(all or lsearch(player if it owns all the cell phones > th lsearch(,ething,\[match(%0,get(##/phonenumber))\]) > ________________________________ >> From: parha...@gmail.com >> To: tinymux@googlegroups.com >> Subject: [TinyMUX] @Foreach Question >> Date: Thu, 3 Jul 2008 22:52:23 +0330
>> Hi, >> I had a question. This is the code of a very simple cellphone I created. >> Every child of generic_cellphone has a number, and this is how the code >> is supposed to work: >> Go through all the children of generic_cellphone with @foreach, and if >> the number attribute on any of them equals the number typed after the >> call command (the command syntax being call *), say connected, else say >> cannot find the target specified. >> Well, as you can see, there is one thing wrong with this algorithm. If >> the generic_cellphone has 100 children, then the fail message will be >> given 99 times. But how can I fix this? >> And is there something like a break command, for example, suppose we have >> three cellphones and the second one matches. The @foreach should stop >> immediately, how can I do that one? >> Thanks! >> --- >> Contact info: >> Skype: parham-d >> MSN: fire_lizard16 at hotmail dot com >> email: parham90 at GMail dot com
> I believe that would be what I'm looking for, but there is no help for > lsearch, and I don't know the syntax, and when I put it in think, it gives > back the same thing to me. I mean this: > lsearch(all,ething,\[match(%0,get(##/phonenumber))\]) > And this is the code I have put, which does nothing: > @va generic_cellphone=$call *:@dolist > [children(num(generic_cellphone))]=ifelse(lsearch(all,ething,\[match(%0,get (##/number))\]),say > works,say doesn't work)
Hello, I TH'ed each part and figured that this, th If(Search(eval=match(1,get(##/NUMBER))),Works,Doesn't work))
works, while EThings doesn't, since it says there is no such thing. So I think what you wanted to put was eval, which evaluates each object. But still, although I know a cellphone with the number 1 exists, this piece of code,
won't work. I've tried the \['s and \]'s, but they don't make a difference either. --- Contact info: Skype: parham-d MSN: fire_lizard16 at hotmail dot com email: parham90 at GMail dot com
----- Original Message ----- From: "A Character" <a_charac...@hotmail.com> To: <tinymux@googlegroups.com> Sent: Friday, July 04, 2008 12:52 PM Subject: [TinyMUX] Re: @Foreach Question
Guess who is used to PennMUSH? That's right, ME! You want 'help search()' for syntax and all that jazz.
And probably something like: @va generic_cellphone=$CALL *:Th Pemit(%#,If(Search(all ething=\[match(%0,get(##/NUMBER))\]),Works,Doesn't work))
> I believe that would be what I'm looking for, but there is no help for > lsearch, and I don't know the syntax, and when I put it in think, it gives > back the same thing to me. I mean this: > lsearch(all,ething,\[match(%0,get(##/phonenumber))\]) > And this is the code I have put, which does nothing: > @va generic_cellphone=$call *:@dolist > [children(num(generic_cellphone))]=ifelse(lsearch(all,ething,\[match(%0,get (##/number))\]),say > works,say doesn't work)=