 |
diehard2k0 Beginner
Joined: 17 Aug 2008 Posts: 25
|
Posted: Sun Aug 17, 2008 7:18 am
Color Fade Alias Works, but small issue. |
Ok, i made an alias to fade colors. It works, but not the way i want it to. The section it colors seems to change, even if the string length doesn't. It seems to get smaller smaller smaller till it reaches 0, then it goes back to normal. An example of what it outputs is
Code: |
Just as a simple test 3 times in a row, nothing changed:
Syntax : csay 1 2 3 4 5 6 7 8 9 0 9 8 7 6 5 4 3 2 1
say &R1 2 3&r 4 5 6&b 7 8 9&B 0 9 8&w 7 6 5&W 4 3 2 1&C
say &R1 2&r 3 4 5&b 6 7 8&B 9 0 9&w 8 7 6&W 5 4 3 2 1&C
say &R1 &r2 3 4 &b5 6 7 &B8 9 0 &w9 8 7 &W6 5 4 3 2 1&C
|
As you can see, the &R section keeps getting smaller and the &W section keeps getting bigger. I can't figure it out. Maybe someone can help?
Note that all this is 1 alias. The variable is just a string list with the color code in there (My mud uses &W for White, and &C for Cyan and so on.) the color string list is @crcr, and is currently 6 colors long.
Code: |
var numcolors {%numitems( @crcr)} {_nodef} {colorfader}
#var cf {} {_nodef} {colorfader}
#LOOP 1,%len( %-1) {#var cf @cf|%copy( %-1, %i, 1)}
#var cfnum {1} {1} {colorfader}
#var cfnum2 {0} {0} {colorfader}
#var cfnum3 {1} {1} {colorfader}
#var cf2 {} {_nodef} {colorfader}
#math cfnum %abs( %round( %float( %len( %-1)/2))*2)
#echo @cfnum
#math cfnum %norm( (@cfnum+0.0)/(@numcolors+0.0))
#add cf2 %item( @crcr, @cfnum3)
#VAR cf %delitem( "", @cf)
#forall @cf {
#math cfnum2 (@cfnum2+1)
#if (@cfnum2>=@cfnum) {
#math cfnum3 (@cfnum3+1)
#add cf2 %item( @crcr, @cfnum3)
#var cfnum2 {0} {_nodef} {}
}
#add cf2 {%i}
}
#add cf2 "&C"
say @cf2 |
[/code] |
|
|
 |
Vijilante SubAdmin

Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sun Aug 17, 2008 11:50 am |
The behavior your showing is usually caused by an uninitialized variable, I don't really see that being the case. You also have lots of unecessary math that is just wasting time. Off the top of my head this script should do what you want
Code: |
#ALIAS csay {
$Pattern=%concat("(.{",(%len(%-1)/%numitems(@crcr)),"})")
#SEND {%concat("say ",%subregex(%-1,$Pattern,"%item(@crcr,(?INSTANCE))\1"),"&C")}
} |
|
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
 |
diehard2k0 Beginner
Joined: 17 Aug 2008 Posts: 25
|
Posted: Sun Aug 17, 2008 6:13 pm |
Vijilante wrote: |
The behavior your showing is usually caused by an uninitialized variable, I don't really see that being the case. You also have lots of unecessary math that is just wasting time. Off the top of my head this script should do what you want
Code: |
#ALIAS csay {
$Pattern=%concat("(.{",(%len(%-1)/%numitems(@crcr)),"})")
#SEND {%concat("say ",%subregex(%-1,$Pattern,"%item(@crcr,(?INSTANCE))\1"),"&C")}
} |
|
Ok, i did try it, and although it doesn't fail, it doesn't quite work either. It adds the &C at the end. I am still learning triggers and all that math was the only way i could figure it out.
If it could be explained as to what certain things do, maybe i could understand this a littler better. $Pattern would be returned as (.{#}) replace # with a number. I got that much. How does ?INSTANCE come into play? I tried reading the helpfile, but it reads like stereo instructions. I will keep tinkering around till i figure it out or unless someone can help, and i will repost here when/if i figure it out. |
|
|
 |
Vijilante SubAdmin

Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sun Aug 17, 2008 10:20 pm |
Hrm,
Quote: |
Ok, i did try it, and although it doesn't fail, it doesn't quite work either. |
What about it doesn't work?
A slightly seperate topic, but we can discuss it here.
Yes, the help for Advanced Subregex reads like stereo instructions. I really need helphful suggestions on properly writing the help for it. I know it is an oxymoron, but I wrote that particular help section. My thinking being a few parts programmer, a few more lawyer, and some stone crafter; I tend to see really fine atom sized pieces; describe those miniscule specks, no one else can see, with a language no one speaks anymore, and finish it up by saying the common phrase for programmers, "It is plainly obvious."
Yes, that help needs help. I actually have a few more things to add to it for 2.36. A few small features got added to %subregex amidst the bug fixes, and they need to be documented so everyone can use them. I really need some ideas on how to explain the concepts in a fashion that makes sense. There were a few commentss, but nothing really said to me, "This is the way normal people would understand it." |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
 |
diehard2k0 Beginner
Joined: 17 Aug 2008 Posts: 25
|
Posted: Sun Aug 17, 2008 11:22 pm |
It doesn't use the @crcr to fade the color. It just takes the input text and addes &C to the end of it.
example
var @crcr = &R|&r|&b|&B|&w|&W
syntax : csay Testing color fade
returns : say Testing color fade&C
should return : &RTes&rtin&bg C&Bolo&wr F&Wade&C
on the other part.
The breakdown for the subregex that I can understand
%-1 - The text after 'csay'
$Pattern - a number based on the length of %-1 divided by the number of items in @crcr
%item - This is where i get a little confused with the ?Instance part. I don't understand what that does.
The helpfile says it is a counter, but how is the counter chaning?
I basically don't see how it is putting the items from @crcr in the string every x letters. It's probably alot
more simple than I'm making it out to be. |
|
|
 |
Vijilante SubAdmin

Joined: 18 Nov 2001 Posts: 5182
|
Posted: Mon Aug 18, 2008 7:58 pm |
I just checked this with 2.36 and the problem appears to be caused by the database character &. Turinng off that character, in the preferences, allows it work properly. Zugg will have to look into the reason that it expands differently when using subregex as opposed to "#SHOW %item(@crcr,1)".
In testing this I did find a small problem in how subregex is reassembling strings for the zScript parser, and will look into that. This particular usage is not affected, but more complex usages show the problem.
To explain how it works, the pattern matches a specified number of characters based on the division. The instance counter counts how many times a match has occured. The combination of those 2 is what puts the correct %item in the correct spot. |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
 |
diehard2k0 Beginner
Joined: 17 Aug 2008 Posts: 25
|
Posted: Mon Aug 18, 2008 11:12 pm |
That did fix it. Thank you. I'm starting to understand the subregex a little more too now. Now comes the fun task of going through all my scripts and seeing where it could possibly fit in.
Thank you again. |
|
|
 |
|
|
|
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
|
|