|  | 
	
	
		| apryl Newbie
 
 
 Joined: 26 Jun 2002
 Posts: 2
 Location: USA
 
 | 
			
			  |  Posted: Wed Jun 26, 2002 8:22 pm 
 need help with text formatting in 6.16
 
 |  
				| Hi. I've been trying to figure this one out for awhile but to no avail. I am using zmud 6.16 and what I want to do is to send a certain @var that contains a string into a function like thing where it'll insert some %ansi colors before certain key words. For example if: 
 @testVar1 = "This is just a test string."
 
 And I want to convert that to:
 
 @testVar1 = "This is just a %ansi(bold,red)test string."
 
 How would I do something like this? It needs to be a function (not necessarily the zmud definition of a function) of some type since I need to call it at more than just one place. Any help would be appreciated! Thanks!
 
 Apryl
 |  | 
	
	  |  | 
	
		|  | 
	
		| Vijilante SubAdmin
 
  
 Joined: 18 Nov 2001
 Posts: 5187
 
 
 | 
			
			  |  Posted: Wed Jun 26, 2002 11:09 pm 
 |  
				| You can use %replace for this quite readily. 
 In your example I would guess "test" is the key word, so the code snippet would be:
 TestVar1=%replace(@TestVar1,"test","%ansi(bold,red)test")
 
 Of course I think you only want the one word colored so...
 TestVar1=%replace(@TestVar1,"test","%ansi(bold,red)test%ansi(default)")
 
 Now for a much more generic function...
 #FU WordColor {%replace(@{%1},"%2","%ansi(%3)%2%ansi(default)")}
 
 That would take your variable name, the word(s) you want colored and the color you want it like this...
 TestVar1="This is just a test string. Test."
 TestVar2=@WordColor(TestVar1,"test","bold,red")
 and the result...
 "This is just a %ansi(bold,red)test%ansi(default) string. Test."
 
 Note that the "test" was replaced, but the "Test" wasn't, %replace is a case-sensitive function.
 |  | 
	
	  |  | 
	
		|  | 
	
		| apryl Newbie
 
 
 Joined: 26 Jun 2002
 Posts: 2
 Location: USA
 
 | 
			
			  |  Posted: Fri Jun 28, 2002 2:01 pm 
 |  
				| Thanks, that actually works well if the @TestVar1 is a string. But I'm running into problems if the string in @TestVar1 references other variables. 
 So for example:
 
 @TestVar1 =
 "@testValue1 is the value1!%cr
 @testValue2 is the value2 of this!"
 
 then I am doing this to set my status window to show the string in @TestVar1:
 
 #stw @TestVar1
 
 All that works fine so far, but I can't figure out how to color the text in @TestVar1. I am doing it this way because @TestVar1 is created on the fly so it's not always the same. So in this example, how would I make the text 'value1' in bold red? I tried your function by doing:
 
 #var TestVar1 @WordColor(TestVar1,"value1","bold,red")
 
 But it seems to go into an infinite loop... something about @TestVar1 referencing other vars in it is messing it up it seems? I hope this made sense, thanks for any help again!
 
 
 Apryl
 |  | 
	
	  |  | 
	
		|  | 
	
		| seamer Magician
 
 
 Joined: 26 Feb 2001
 Posts: 358
 Location: Australia
 
 | 
			
			  |  Posted: Fri Jun 28, 2002 5:05 pm 
 |  
				| have you tried recording variables with ansi already in them?  from what i can see, #stw doesnt do any kind of formatting with colour beyond %ansi...<muddled head aura> 
 maybe an example of what you wanted to do would help get more jucier answers *stares at the sky*
 
 Why oh WHY did I have pass door on...
 |  | 
	
	  |  | 
	
		|  | 
	
		| Vijilante SubAdmin
 
  
 Joined: 18 Nov 2001
 Posts: 5187
 
 
 | 
			
			  |  Posted: Fri Jun 28, 2002 10:07 pm 
 |  
				| I really should stop opening cans of worms. 
 #FU WordColor {%replace(%expand(@{%1},1),"%2","%ansi(%3)%2%ansi(default)")}
 
 The expand function allow you to control how much gets expanded.  That sounded really lame, anyhow that would give all the info in testvar1 to to the replace, but leave @testValue1 and @testValue2 as variable references.
 |  | 
	
	  |  | 
	
		|  | 
	
		| seamer Magician
 
 
 Joined: 26 Feb 2001
 Posts: 358
 Location: Australia
 
 | 
			
			  |  Posted: Sat Jun 29, 2002 2:54 pm 
 |  
				| my turn for a question   
 %ansi( green, bold)Bot Status: %ansi( magenta, bold)%proper( @afk)
 %ansi( green, bold)EQ: %ansi( magenta, bold)%upper( @eq)%cr
 %ansi( brown)Wielding: %ansi( white)%proper( @weap)
 %ansi( brown)Position: %ansi( white)%proper( @awake)%cr
 %ansi( red, bold)%upper( @lethargy%cr@haste)%cr%cr
 %ansi( blue, bold)Protectives:%ansi( gray)%cr%upper( @sanctuary)%cr@bless%cr@fly%cr@protectevil%cr@protectgood%cr@shield%cr@stoneskin%cr@armor%cr%cr%ansi( 159)@regen%cr@talon%cr@giant%ansi( 0)%cr%cr
 %ansi( cyan)Improved:%ansi( white)
 #FORALL @better {%i}
 #SHOW ""
 
 this sits in my #stw, and the only broken bit is the #forall...how would i make it print this variable nicely with each value on its own line?  i can see at least 2 uses for it, tracking spells/skills i improve in a session, and record if any equipment gets damaged..just cant get it right
 can ye help?
 
 Why oh WHY did I have pass door on...
 |  | 
	
	  |  | 
	
		|  | 
	
		| Kjata GURU
 
  
 Joined: 10 Oct 2000
 Posts: 4379
 Location: USA
 
 | 
			
			  |  Posted: Sat Jun 29, 2002 3:08 pm 
 |  
				| Try using: %expandlist(@better, %crlf)
 
 instead of the #FORALL
 
 Kjata
 |  | 
	
	  |  | 
	
		|  | 
	
		| Vijilante SubAdmin
 
  
 Joined: 18 Nov 2001
 Posts: 5187
 
 
 | 
			
			  |  Posted: Sat Jun 29, 2002 10:24 pm 
 |  
				| You can also swap that line with this %replace(@better,"|",%cr).  The status window does not preform any commands, hence everything must be done using functions and variables. 
 |  | 
	
	  |  | 
	
		|  | 
	
		| seamer Magician
 
 
 Joined: 26 Feb 2001
 Posts: 358
 Location: Australia
 
 | 
			
			  |  Posted: Sun Jun 30, 2002 1:32 am 
 |  
				| sweet, both suggestions work..big thanks   
 Why oh WHY did I have pass door on...
 |  | 
	
	  |  | 
	
		|  | 
	
		|  | 
	
		|  |