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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
Anzerion
Beginner


Joined: 06 May 2003
Posts: 19
Location: USA

PostPosted: Fri Dec 29, 2006 3:53 am   

problem with script -- #IF and #PCOL
 
This script worked perfect on zMud as it is shown here, and now it doesn't work exactly how it's supposed to...

#TRIGGER {We'll pay you (%n) gold for that.} {
#IF {%1 > 0} {#PCOL mxplightsteelblue %x1} {}
#IF {%1 > 1000000} {#PCOL mxplightblue %x1} {}
#IF {%1 > 2000000} {#PCOL mxplightcyan %x1} {}
#IF {%1 > 3500000} {#PCOL mxpfirebrick %x1} {}
#IF {%1 > 5500000} {#PCOL mxpyellow %x1} {}
#IF {%1 > 7500000} {#PCOL mxpred %x1} {}
#IF {%1 > 8500000} {#PCOL mxpmagenta %x1} {}
}

Okay -- that's exactly how it was in zMud, haven't changed anything. An example of what it's modifying is:

A covered wagon horse can carry 24 chests of tools. We'll pay you 1,778,112 gold for that.
A covered wagon horse can carry 11 crates of adamantite. We'll pay you 3,056,064 gold for that.
A covered wagon horse can carry 21 sacks of coal. We'll pay you 1,750,392 gold for that.
A covered wagon horse can carry 48 sacks of poppyseed. We'll pay you 2,889,504 gold for that.
A covered wagon horse can carry 7 sacks of iron. We'll pay you 388,920 gold for that.

So for instance, 388k would be highlighted lightsteelblue. 3m would be highlighted lightcyan, and 1.7m would be hightlighted lightblue.

The problem with this script though is that the lines are all being hightlighted the last color. IE, right now... "388,920 gold for that." is being highlighted magenta, as well as every other line ("2,889,504 gold for that.")

If I delete the #IF line that highlights numbers greater than 8.5m, it uses the next color, which is red, even though none of them are greater than 7.5 million.

So my two questions are... how do I get this working in CMUD, and how do I get it also to only highlight the number, not the "gold for that." part.

Thanks!
Reply with quote
crycry
Apprentice


Joined: 24 Jun 2006
Posts: 169
Location: UK - South Coast

PostPosted: Fri Dec 29, 2006 12:15 pm   
 
First thing that immediately strikes me is that you dont want {} in your IF condition statement, it needs to be #IF (xxx) {} {}. thats likely to be causing some troubles because of the more syntax correct way that cMud handles things.
_________________
'Life is what happens, when your too busy doing something else'

_________________

XP Pro SP2
cMud 1.24
_________________
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Fri Dec 29, 2006 12:58 pm   
 
The #IF does seem to be slightly odd, even after fixing it so it's
#if (expr) {then} {else}
rather than if {expr}...

Anyway, this seems like an opportunity to use #SWITCH instead of #IF
Code:
#SWITCH (%1 > 8500000) {#PCOL mxpmagenta %x1}
  (%1 > 7500000) {#PCOL mxpred %x1}
  (%1 > 5500000) {#PCOL mxpyellow %x1}
  (%1 > 3500000) {#PCOL mxpfirebrick %x1}
  (%1 > 2000000) {#PCOL mxplightcyan %x1}
  (%1 > 1000000) {#PCOL mxplightblue %x1}
  (%1 > 0) {#PCOL mxplightsteelblue %x1}
Which works properly
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)

Last edited by Guinn on Fri Dec 29, 2006 6:09 pm; edited 1 time in total
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Fri Dec 29, 2006 2:27 pm   
 
So randomly I decided to see if I could get CMUD to be a bit more intelligent about what colour to have things
The following will take it's base colour to be $FF0000 (red) and as the matched value rises from 0 towards 850000 then the colour will gradually get lighter, through orange, yellow towards white.
Note - this will not ever work in zMUD, because it uses local variables and the #SWITCH command ;)

Code:
#TRIGGER {We'll pay you (%n) gold for that.} {
#LOCAL $colour, $max, $temp, $first, $second
$max = 8500000
#IF (%1 >= $max) {colour = FFFFFF} {
  $temp = (%1*256/$max)
  $first = ($temp/16)
  $second = %mod($temp, 16)

  #SWITCH ($first)
    10 {$first = A}
    11 {$first = B}
    12 {$first = C}
    13 {$first = D}
    14 {$first = E}
    15 {$first = F}

  #SWITCH ($second)
    10 {$second = A}
    11 {$second = B}
    12 {$second = C}
    13 {$second = D}
    14 {$second = E}
    15 {$second = F}
 
  $colour = %concat(FF, $first, $second)
}

#EXEC {#PCOL $$colour %x1}
}

Might be useful, might not. Was more curious if it'd work ;)
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)

Last edited by Guinn on Fri Dec 29, 2006 6:12 pm; edited 2 times in total
Reply with quote
Anzerion
Beginner


Joined: 06 May 2003
Posts: 19
Location: USA

PostPosted: Fri Dec 29, 2006 4:04 pm   
 
I tried the script immediately above, Guinn, and only got 'ERROR: Trigger We'll pay you (%n) gold for that. fired but did not compile'

Trying the first one you replied with now though.

Okay, the #SWITCH substitution doesn't work either. ;-/ Same error message, that it did not compile.

Trying now just fixing syntax. Okay -- I changed the syntax as crycry and you suggested, and it works for everything from 0 to 1 million (it correctly highlights only the number lightsteelblue.) However, everything above 1 million is also lightsteelblue, and not just the number -- the number and the rest of the line.

Okay... oddly enough, I had copy/pasted the script above and reversed the order from 8.5 million to 0 instead of 0 to 8.5 million -- so I switched it back around. It now looks like this:

#IF (%1 > 0) {#PCOL mxplightsteelblue %x1}
#IF (%1 > 1000000) {#PCOL mxplightblue %x1}
#IF (%1 > 2000000) {#PCOL mxplightcyan %x1}
#IF (%1 > 3500000) {#PCOL mxpfirebrick %x1}
#IF (%1 > 5500000) {#PCOL mxpyellow %x1}
#IF (%1 > 7500000) {#PCOL mxpred %x1}
#IF (%1 > 8500000) {#PCOL mxpmagenta %x1}

And it works like that -- except the only instance when just the number is highlighted is anything greater than 0, then just the number is lightsteelblue. If it's anything else, the right color is used, but the number and the "gold for that." is also highlighted.

Thanks for the replies thus far!
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Fri Dec 29, 2006 6:09 pm   
 
Ahh, the switch one got messed up by the phpbb formatting which removed the spaces from the start of the line - I've corrected it in my first post to stop the code being altered.
The 2nd one should just work when pasted right onto the command line - I just tried on another machine and it worked without a hitch.

Looks like it might be a bug with #IF. #SWITCH should work fine though now I've tidied up the bb formatting
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)
Reply with quote
Anzerion
Beginner


Joined: 06 May 2003
Posts: 19
Location: USA

PostPosted: Fri Dec 29, 2006 7:47 pm   
 
Okay... I got the gradual script to work -- you had an error in the syntax that was keeping it from working. ($$colour instead of $colour) Oddly enough, CMUD accepts colour as well as color ;-)

Anyway, the script works as far as colors go... but it doesn't highlight the numbers, instead it highlights the last number of the figure and then highlights the "gold for that." part. The colors don't look as great either.



The first #SWITCH script you posted just doesn't work at all -- says it fires but did not compile. If I add #SWITCH before every line, then it highlights everything lightsteelblue (the last one on the list, regardless of whether or not it's greater than say 3.5 million instead of just 0.) So I guess you have to have #SWITCH before every line as, in...

#SWITCH (%1 > 8500000) {#PCOL mxpmagenta %x1}
#SWITCH (%1 > 7500000) {#PCOL mxpred %x1}
#SWITCH (%1 > 5500000) {#PCOL mxpyellow %x1}
#SWITCH (%1 > 3500000) {#PCOL mxpfirebrick %x1}
#SWITCH (%1 > 2000000) {#PCOL mxplightcyan %x1}
#SWITCH (%1 > 1000000) {#PCOL mxplightblue %x1}
#SWITCH (%1 > 0) {#PCOL mxplightsteelblue %x1}

I mean, at least then it fires and compiles -- albeit doing it wrong and disregarding the correct colors. The same thing happens using #IF though as well.

Okay -- I have finally gotten it to work perfectly. It now -only- hightlights the numbers and leaves the "gold for that." part green.

Code:
#TRIGGER {We'll pay you (%n) gold for that.} {
  #IF (%1 > 0) {#PCOL mxplightsteelblue %x1 %x2}
  #IF (%1 > 1000000) {#PCOL mxplightblue %x1 %x2}
  #IF (%1 > 2000000) {#PCOL mxplightcyan %x1 %x2}
  #IF (%1 > 3500000) {#PCOL mxpfirebrick %x1 %x2}
  #IF (%1 > 5500000) {#PCOL mxpyellow %x1 %x2}
  #IF (%1 > 7500000) {#PCOL mxpred %x1 %x2}
  #IF (%1 > 8500000) {#PCOL mxpmagenta %x1 %x2}
}


I'm not really sure what the %x2 is referring to, but I'm guessing it tells the script to stop the PCOL command at the second word, hence only the first is highlighted.

Thanks for the help guys!
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Fri Dec 29, 2006 8:47 pm   
 
The $$colour wasn't an error. It was because $colour indicates a local variable which happened to contain a colour code. To use #PCOL with a hex colour code you prefix the code with a $. To get that syntax to work you place it inside the #EXEC to force expansion - so $$colour was correct.

When using #SWITCH you don't put #SWITCH on every line, that way you may as well just use #IF. The way switch works is that it goes through each test expression until it finds one which matches, then it stops.

Dunno what's causing the problem, the syntax is fine and with the switch, works a treat on my system with a clean session - see attached.
Anyone else able to test, because if CMUD is giving inconsistent results between machines for things as trivial as a #SWITCH command that's not good.

http://www.filefactory.com/file/335f0a/
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)
Reply with quote
Anzerion
Beginner


Joined: 06 May 2003
Posts: 19
Location: USA

PostPosted: Fri Dec 29, 2006 9:06 pm   
 
Okay, I tried the switch trigger again, made sure all the spacing was exactly correct -- I think I must have forgotten the spaces before the second and on lines. Nonetheless, the switch script does work exactly the same as that last script I posted -- no noticeable difference (not that there should be.)

I tried the gradual script again too -- this time I turned off syntax highlight which really interferes with seeing the spacing... that seemed to do the trick again, wrong spacing on a line seems to screw the whole thing up and syntax highlighting makes lining everything up much more difficult. However, I like the pcol better because the colors are easier to differentiate.

Thanks though! Btw, Vista interface looks really nice !! ;-D
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum 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