TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

Using functions for color codes.

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> General Discussion
View previous topic :: View next topic  
Author Message
shal



Joined: 06 Mar 2007
Posts: 3

PostPosted: Tue Mar 06, 2007 2:07 pm    Post subject: Using functions for color codes. Reply with quote

I'm trying to use the #prompt function to sub my prompt. Currently what I have is:

#PROMPT {^%0h, %1m, %2e, %3w %4-} {<@hcolour>"$health"h, <@mcolour>"$mana"m, <@ecolour>{"@endurance"%}e, <@wcolour>{"@willpower"%}w - @pdefs}

#function {hcolour} {
#if {"$health" > "@h1"} {
#var result 120} {
#if {"$health" > "@h2"} {
#var result 130} {
#if {$health >= 1} {
#var result 110} {
#if {"$health" == "0"} {
#var result 007
}}}}}

The functions determine the colour, but all that it gives me is:

<@hcolour>"3066"h, <@mcolour>"3146"m, <@ecolour>{"@endurance"%}e, <@wcolour>{"@willpower"%}w - @pdefs

I also tried using variables instead of functions, that didn't work either. Is there any way to use functions to determine color codes in substitutions?
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3770

PostPosted: Tue Mar 06, 2007 2:54 pm    Post subject: Reply with quote

You can't use a function from within another function, which is your main problem.

You're also doing a string comparison, so drop the quotes as in: #if {$health == 0} instead of #if {"$health" == "0"}

You might want to look at this example script from the webpage: http://tintin.sourceforge.net/scripts/promptbar.php
Back to top
View user's profile Send private message Send e-mail
shal



Joined: 06 Mar 2007
Posts: 3

PostPosted: Tue Mar 06, 2007 3:14 pm    Post subject: Reply with quote

I rewrote the hcolour function:

#function {hcolour} {
#if {$health > $h1} {
#var result 120} {
#if {$health > $h2} {
#var result 130} {
#if {$health >= 1} {
#var result 110} {
#if {$health == 0} {
#var result 007
}}}}}

However, I still get the same error.
Back to top
View user's profile Send private message
shal



Joined: 06 Mar 2007
Posts: 3

PostPosted: Tue Mar 06, 2007 5:01 pm    Post subject: Reply with quote

Ok, I messed around with different ways of writing it and I got this:

#function {pcolour} {
#format result %m {&1 / 1.3};
#if {&0 > $result} {
#var result 120} {
#format result %m {&1 / 3};
#if {&0 > $result} {
#var result 130} {
#if {&0 >= 1} {
#var result 110} {
#if {&0 == 0} {
#var result 007
}}}}}

This gives me a prompt of

<120>3066, <120>3183, <120>"@endurance"%, <120>"@willpower"% - @pdefs

Now it's correctly substituting the color code, but it isn't processing it. Is there a way to force it to process the color code?
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3770

PostPosted: Tue Mar 06, 2007 5:30 pm    Post subject: Reply with quote

shal wrote:

Now it's correctly substituting the color code, but it isn't processing it. Is there a way to force it to process the color code?


Looks like you'll have to include the < > tags in the function and remove them from the prompt trigger:

Code:

#function         {pcolour}               {
 #format result %m {&1 / 1.3};
 #if {&0 > $result} {
  #var result <120>} {
   #format result %m {&1 / 3};
   #if {&0 > $result} {
    #var result <130>} {
     #if {&0 >= 1} {
      #var result <110>} {
       #if {&0 == 0} {
        #var result <007>
       }}}}}


To nest if checks more neatly you can skip the braces for the else part of the if check:

Code:

#function {pcolour}
{
  #if {&0 > &1 / 1.3}
  {
    #var result <120>
  }
  #if {&0 > &1 / 1.3}
  {
    #var result <130>
  }
  #if {&0 >= 1}
  {
    #var result <110>
  }
  #if {&0 == 0}
  {
    #var result <007>
  }
}
Back to top
View user's profile Send private message Send e-mail
davevnj



Joined: 22 Nov 2006
Posts: 55

PostPosted: Tue Mar 06, 2007 6:45 pm    Post subject: Reply with quote

I have similar ugly if/else logic.

Does the
Code:
  #if {}
  {
  }
  #if {}
  {
  }
  #if {}
  {
  }

behave like an if/else chain or does it check each condition every time (like multiple if statements? If it is an if/else chain, I'd assume ;'s would separate them into multiple if statements, right?
Back to top
View user's profile Send private message Visit poster's website
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3770

PostPosted: Wed Mar 07, 2007 6:47 am    Post subject: Reply with quote

davevnj wrote:

Does the code behave like an if/else chain or does it check each condition every time (like multiple if statements? If it is an if/else chain, I'd assume ;'s would separate them into multiple if statements, right?

It's a nested chain. Tintin expects braces to separate the first and second argument, but the 3rd argument is taken in it's entirety regardless of braces.

Adding ;'s would indeed separate them in multiple statements.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> General Discussion All times are GMT - 5 Hours
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
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group