Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
ecourt
Apprentice


Joined: 29 Dec 2000
Posts: 146
Location: USA

PostPosted: Mon Dec 29, 2008 3:03 am   

string stuff
 
is there an easy way to take a string that came from the mud into a variable list ?

if %1 = a handful of rubies
can I add it to a list variable so that
list[1] = a
list[2] = handful
list[3] = of
list[4] = rubies

Thanks
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Mon Dec 29, 2008 3:18 am   
 
Yep.

List = %replace(%1," ","|")

You could also use %subchar if you like. You can then use %item to get an item back out of the list, and #forall to iterate over the list.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
ecourt
Apprentice


Joined: 29 Dec 2000
Posts: 146
Location: USA

PostPosted: Mon Dec 29, 2008 4:30 am   
 
hummmm ... using this....

#additem aa %replace( %2, " ", "|")

#echo %item(@aa,1) produces

a|handful|of|rubies

It's not reading the | as seperators ? --maybe add an #eval ?
Reply with quote
ecourt
Apprentice


Joined: 29 Dec 2000
Posts: 146
Location: USA

PostPosted: Mon Dec 29, 2008 4:35 am   
 
Nevermind... :) Figured it out...
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon Dec 29, 2008 10:00 pm   
 
The reason it's not reading the | as separators is because you effectively added a stringlist to a stringlist, which results in nesting (the stringlist being added is automatically surrounded by parentheses.)

If you don't want nested stringlists, you either have to add each individual item separately or perhaps use %replace() or %remove() to pull the parentheses out after the additem.
_________________
EDIT: I didn't like my old signature
Reply with quote
ecourt
Apprentice


Joined: 29 Dec 2000
Posts: 146
Location: USA

PostPosted: Mon Dec 29, 2008 10:04 pm   
 
reason I did it that way, I was reading the docs for #additem, it said #additem aa 1|2|3|4 would work correctly... or I misread it... anyway, it works now.
Reply with quote
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Mon Dec 29, 2008 10:24 pm   
 
Why not do

Code:

#forall %replace(%2, " ", "|") {#additem aa %i}


instead?
_________________
The Proud new owner of CMud.

--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
--------------------------------
Reply with quote
ecourt
Apprentice


Joined: 29 Dec 2000
Posts: 146
Location: USA

PostPosted: Mon Dec 29, 2008 10:43 pm   
 
why loop, when you don't have to ?

List = %replace(%1," ","|") works just fine.
Reply with quote
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Tue Dec 30, 2008 12:06 am   
 
ecourt wrote:

hummmm ... using this....

#additem aa %replace( %2, " ", "|")

#echo %item(@aa,1) produces

a|handful|of|rubies

It's not reading the | as seperators ? --maybe add an #eval ?


Basically it was reply regarding this. My apologizes if I misunderstood.
_________________
The Proud new owner of CMud.

--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
--------------------------------
Reply with quote
ecourt
Apprentice


Joined: 29 Dec 2000
Posts: 146
Location: USA

PostPosted: Tue Dec 30, 2008 12:17 am   
 
no need for apologizes.. it's all good :D
Reply with quote
ecourt
Apprentice


Joined: 29 Dec 2000
Posts: 146
Location: USA

PostPosted: Sun Jan 04, 2009 2:09 pm   
 
I'm working on something else now, but have run into an issue with %replace....

I'm sending a web address, with a get ...

so my webadr varable looks like this

www.web.com/add.php?name=a glittering ruby ring&worn=finger

so I take the variable and do this

webadr = %replace( @webadr, " ", "%20")

which should look like this

www.web.com/add.php?name=a%20glittering%20ruby%20ring&worn=finger

but instead, it looks like this

www.web.com/add.php?name=aglitteringrubyring&worn=finger


Any thoughts ?
Thanks
Reply with quote
calesta
Apprentice


Joined: 07 Dec 2008
Posts: 102
Location: New Hampshire, USA

PostPosted: Sun Jan 04, 2009 3:40 pm   
 
The %replace actually works fine, its during the assignment that the expression on the right is evaluated where you lose the %20 I believe. I actually lose the &word when I try it as well since that is the Database character by default. Adding a ~ in front of the % and & worked for me:
Code:
webadr = %replace(%replace(@webadr,"&","~&")," ","~%20")
.
Reply with quote
ecourt
Apprentice


Joined: 29 Dec 2000
Posts: 146
Location: USA

PostPosted: Sun Jan 04, 2009 3:47 pm   
 
thanks, I'll give it a shot...
Reply with quote
ecourt
Apprentice


Joined: 29 Dec 2000
Posts: 146
Location: USA

PostPosted: Sun Jan 04, 2009 5:27 pm   
 
hummm --- you were right, the & is causing a problem, but the ~ isn't fixing it...

Code:

stuff.name = a golden sceptre
stuff.type = LIGHT
webadr = www.web.com/add.php?name=@stuff.name~&type=@stuff.type
webadr = %replace(@webadr," ", "~%20")


#echo @webadr shows this
www.web.com/add.php?name=a%20golden%20sceptre=LIGHT

It's totally skipping the word type.
Reply with quote
calesta
Apprentice


Joined: 07 Dec 2008
Posts: 102
Location: New Hampshire, USA

PostPosted: Sun Jan 04, 2009 6:39 pm   
 
You're doing a double assignment to webadr. Your first assignment puts the ~ in front of the & correctly. The second assignment with the %replace doesn't put the ~ back in front of the & (it was removed by the evaluation of the right side of the first assignment). If you do the double replace like I did in the example I posted before, that should fix the problem.

The reason it looks like it's skipping the word type is that the & makes zMUD think the following word is the name of a database variable. Since it's not, a null value ends up going in its place which makes it look like the word was skipped.
Reply with quote
ecourt
Apprentice


Joined: 29 Dec 2000
Posts: 146
Location: USA

PostPosted: Sun Jan 04, 2009 11:29 pm   
 
works the same with or without it.
tried it both ways.
Reply with quote
ecourt
Apprentice


Joined: 29 Dec 2000
Posts: 146
Location: USA

PostPosted: Sun Jan 04, 2009 11:43 pm   
 
even tried
Code:

#var webadr 'www.web.com/add.php?name=@stuff.Name$type=@stuff.type
#echo -before- @webadr
webadr = %replace( %replace( @webadr, "$", "~&"), " ", "~%20")
#echo -after- @webadr
#url @webadr

which shows
-before- 'www.web.com/add.php?name=a golden sceptre$type=LIGHT
-after- 'www.web.com/add.php?name=a%20golden%20sceptre=LIGHT
Reply with quote
calesta
Apprentice


Joined: 07 Dec 2008
Posts: 102
Location: New Hampshire, USA

PostPosted: Mon Jan 05, 2009 12:09 am   
 
Hrm, sorry. I forgot this was the zMUD thread and was testing it in CMUD where it works fine. I have the same problem with it that you're describing when doing it in zMUD and so far haven't figured out how to fix it.
Reply with quote
ecourt
Apprentice


Joined: 29 Dec 2000
Posts: 146
Location: USA

PostPosted: Mon Jan 05, 2009 12:14 am   
 
I wish I could use cmud... it crashes so often it's unusable. started several threads, but no one has ever been able to help.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Mon Jan 05, 2009 1:08 am   
 
It just struck me, doubling up the & character might quote it. So try && instead.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
calesta
Apprentice


Joined: 07 Dec 2008
Posts: 102
Location: New Hampshire, USA

PostPosted: Mon Jan 05, 2009 1:28 am   
 
I just tried out that idea and it doesn't work either... you end up with this (note the missing 'type' after the &):

www.web.com/add.php?name=a%20golden%20sceptre&=LIGHT

If you're not using database variables you can go into preferences and turn off the database variable character on the special characters screen and it seems to work. You could also change the database character from & to something else I imagine... but that would involve changing any scripts you have that make use of the & database character plus you could mess others things up if you choose the new character badly...
Reply with quote
ecourt
Apprentice


Joined: 29 Dec 2000
Posts: 146
Location: USA

PostPosted: Mon Jan 05, 2009 1:48 am   
 
I don't use any db stuff..the website I send the data to has a mysql back-end, and much better stuff :)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net