|
Meylot Newbie
Joined: 20 Jun 2007 Posts: 5 Location: Somewhere in Middle Europa
|
Posted: Thu Dec 27, 2007 5:29 pm
vars and funcs eat spaces in params |
Like in subject: When i give a string as parameter to the variable or function it eats all spaces. My case below:
Code: |
#FO @druzyna_m {
#SH {@odmien_b(%i)}
}
|
in @druzyna_m i've got for egzample "big gray wolf|thick thin man"
and odmien_b is my variable or function that returns each word changed with polish grammar
As I noticed odmien_b receives the string without spaces eg "biggraywolf" and "thickthinman".
Why is it like that and how to force receiving spaces? |
|
|
|
Dharkael Enchanter
Joined: 05 Mar 2003 Posts: 593 Location: Canada
|
Posted: Fri Dec 28, 2007 2:48 am |
I would like to see what's going on in your odmien_b function.
Using CMUD 2.18
And putting in this code
Code: |
#var druzyna_m "big gray wolf|thick thin man"
#FUNC odmien_b {%numparam():%param(1)}
#FO @druzyna_m {
#SH {@odmien_b(%i)}
} |
I got this back:
Code: |
1:big gray wolf
1:thick thin man |
Spaces have been preserved
Maybe if you show us what's going on in the odmien_b function we can figure out why your whitespaces are being consumed. |
|
_________________ -Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style." |
|
|
|
JohnEnnion Newbie
Joined: 24 Sep 2004 Posts: 6
|
Posted: Fri Dec 28, 2007 7:46 am |
Code: |
#ALARM +1 {#T- elixlist;#LOOPDB @elixlist {#SA %switch(%val < 40, %ansi(bold,red)You have %val %key sips remaining., %val > 40, %ansi(bold,green)You have %val %key sips remaining.)}} |
Produces
Code: |
Youhave111manasipsremaining.
Youhave16speedsipsremaining.
Youhave576healthsipsremaining.
Youhave108levitationsipsremaining.
Youhave204mendingsipsremaining.
Youhave72epidermalsipsremaining.
Youhave28immunitysipsremaining.
Youhave69restorationsipsremaining.
Youhave34caloricsipsremaining. |
I'm a little baffled myself. Doesn't seem to be a problem until the %switch and %ansi come in.
Not sure if this is related to OP. |
|
|
|
Dharkael Enchanter
Joined: 05 Mar 2003 Posts: 593 Location: Canada
|
Posted: Fri Dec 28, 2007 8:22 am |
Try this
Code: |
#ALARM +1 {#T- elixlist;#LOOPDB @elixlist {#SA %switch(%val < 40,%concat(%ansi(bold,red),"You have ",%val," ",%key," sips remaining."), %val > 40,%concat(%ansi(bold,green),"You have ",%val," ",%key," sips remaining."))}} |
|
|
_________________ -Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style." |
|
|
|
JohnEnnion Newbie
Joined: 24 Sep 2004 Posts: 6
|
Posted: Fri Dec 28, 2007 9:14 am |
Dharkael wrote: |
Try this
Code: |
#ALARM +1 {#T- elixlist;#LOOPDB @elixlist {#SA %switch(%val < 40,%concat(%ansi(bold,red),"You have ",%val," ",%key," sips remaining."), %val > 40,%concat(%ansi(bold,green),"You have ",%val," ",%key," sips remaining."))}} |
|
Thank you so much, and now I know the proper use for that function, sorry for sticking this in what was most likely an unrelated thread. |
|
|
|
Meylot Newbie
Joined: 20 Jun 2007 Posts: 5 Location: Somewhere in Middle Europa
|
Posted: Fri Dec 28, 2007 3:01 pm |
Dharkael
Thanks for response, Your code realy worked fine, so it must be my mistake. I was using the other way to receive parameters (not %param(1) like you). I made each setting from zero and everything works now properly. I just have to read more about functions ;).
Sorry for trouble and thanks for Your help. :) |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Fri Dec 28, 2007 3:45 pm |
Your script won't work properly if a vial contains exactly 40 sips, since you're using < and >. But since you only want it to use two colours (one for less than 40, one for everything else) you can use %if instead. And also, why repeat yourself?
#ALARM +1 {#T- elixlist;#LOOPDB @elixlist {#SA %concat(%if(%val < 40,%ansi(bold,red),%ansi(bold,green)),"You have ",%val," ",%key," sips remaining.")}} |
|
|
|
JohnEnnion Newbie
Joined: 24 Sep 2004 Posts: 6
|
Posted: Fri Dec 28, 2007 5:30 pm |
Fang Xianfu wrote: |
Your script won't work properly if a vial contains exactly 40 sips, since you're using < and >. But since you only want it to use two colours (one for less than 40, one for everything else) you can use %if instead. And also, why repeat yourself?
#ALARM +1 {#T- elixlist;#LOOPDB @elixlist {#SA %concat(%if(%val < 40,%ansi(bold,red),%ansi(bold,green)),"You have ",%val," ",%key," sips remaining.")}} |
Because I'm still getting the hang of writing scripts, thank you so much for the additional input :> |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Fri Dec 28, 2007 6:09 pm |
Any time that you want CMUD to keep spaces in strings, you must enclose each string with " ". That's why your code wasn't working, and that's why it was changed to "You have ",%val," ",%key," sips remaining."
Charneus |
|
|
|
|
|
|
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
|
|