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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Tue Nov 04, 2008 7:21 pm   

Invalid Local Variable Error
 
I keep getting hp_string (and presumably the other local strings as well) as an invalid local variable . I tried using concat, before it was the same thing as it is with the concat, but without it which I thought might be making difficulties turning it into a string. However, adding the concat file didn't work. What am I doing wrong?

Code:

#GAGLOG
time=%1

#IF (((@hp_max/@hp_curr)<0.75) AND ((@hp_max/@hp_curr)>=0.50))
{
 $hp_string=%concat(%ansi(hi, yellow),@hp_curr,%ansi(reset),"/",@hp_max,%ansi(hi, red),"hp",%ansi(reset))
}
#IF ((@hp_max/@hp_curr)<0.50)
{
 $hp_string=%concat(%ansi(hi, red),@hp_curr,%ansi(reset),"/",@hp_max,%ansi(hi, red),"hp",%ansi(reset))
}

#IF (((@mana_max/@mana_curr)<0.75) AND ((@mana_max/@mana_curr)>=0.50))
{
 $mana_string=%ansi(hi, yellow)@mana_curr%ansi(reset)/@mana_max%ansi(hi, blue)mana%ansi(reset)
}
#IF ((@mana_max/@mana_curr)<0.50)
{
 $mana_string=%ansi(hi, red)@mana_curr%ansi(reset)/@mana_max%ansi(hi, blue)mana%ansi(reset)
}

#IF (((@mv_max/@mv_curr)<0.75) AND ((@mv_max/@mv_curr)>=0.50))
{
 $mv_string=%ansi(hi, yellow)@mv_curr%ansi(reset)/@mv_max%ansi(gray)mv%ansi(reset)
}
#IF ((@mv_max/@mv_curr)<0.50)
{
 $mv_string=%ansi(hi, red)@mv_curr%ansi(reset)/@mv_max%ansi(gray)mv%ansi(reset)
}

#IF (@combat=1)
{
 #WRITELOG " "
 #WRITELOG > @Time | $hp_string | $mana_string |$mv_String
 #WRITELOG " "
}
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
intoK
Apprentice


Joined: 18 Feb 2007
Posts: 190

PostPosted: Tue Nov 04, 2008 8:01 pm   
 
youre declaring locals inside one lexical scope and using them outside...
ie. put #LOCAL $mv_string etc below #GAGLOG but before #IFs
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Tue Nov 04, 2008 8:03 pm   
 
I put them without the local command and it didn't work, I'll try with local.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Tue Nov 04, 2008 8:19 pm   
 
Well, no errors, but the string variables are empty:

> 3:00am | | |
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
intoK
Apprentice


Joined: 18 Feb 2007
Posts: 190

PostPosted: Tue Nov 04, 2008 8:36 pm   
 
thats probably because you need to refresh your maths Razz

swap divisions operands to get fraction
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Tue Nov 04, 2008 9:00 pm   
 
So I switched that around aaand...

Quote:

> 7:30am | 767/1626hp | 0 |


> 7:30am | 767/1626hp | 1278/1492mana | 406/406mv


No color, I think that I'm using concat wrong, but I'm not sure what to do.

_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Tue Nov 04, 2008 9:05 pm   
 
Heh, that's some clever observation there intoK - I didn't spot that!

You might find it useful as well to change your use of normal variables to local ones, like

$hp_curr=@hp_curr
$hp_max=@hp_max

and then use the local versions rather than general versions during your script. Since you're using each variable quite a few times throughout the script, you may see an improvement in speed.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
intoK
Apprentice


Joined: 18 Feb 2007
Posts: 190

PostPosted: Tue Nov 04, 2008 9:38 pm   
 
cheers, i gave more optimized code with inline %switch in other thread earlier too

well, it works perfectly fine, but youre logging as html and writing ansi colour codes into it

you need to use html colour tags instead, ie. <span style="color:yellow;">blah blah</span>
Razz
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Tue Nov 04, 2008 10:12 pm   
 
Oh, I figured CMUD converted the ansi output from the MUD into html, but I suppose when I'm writing directly to the log...
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Tue Nov 04, 2008 10:45 pm   
 
This is the ugly beast it has become, still no color though, neither in the editor or when I open it in my browser.

Code:

#GAGLOG
time=%1
#LOCAL $hp_string
#LOCAL $mana_string
#LOCAL $mv_string

#IF (((@hp_curr/@hp_max)<0.75) AND ((@hp_curr/@hp_max)>=0.50))
{
 $hp_string=%concat(<font color='yellow'>,@hp_curr,</font>,"/",@hp_max,<font color='red'>,"hp",</font>)
}
#IF ((@hp_curr/@hp_max)<0.50)
{
 $hp_string=%concat(<font color='red'>,@hp_curr,</font>,"/",@hp_max,<font color='red'>,"hp",</font>)
}

#IF (((@mana_curr/@mana_max)<0.75) AND ((@mana_curr/@mana_max)>=0.50))
{
 $mana_string=%concat(<font color='yellow'>,@mana_curr,</font>,"/",@mana_max,<font color='blue'>,mana,</font>)
}
#IF ((@mana_curr/@mana_max)<0.50)
{
 $mana_string=%concat(<font color='red'>,@mana_curr,</font>,"/",@mana_max<font color='blue'>mana</font>)
}

#IF (((@mv_curr/@mv_max)<0.75) AND ((@mv_curr/@mv_max)>=0.50))
{
 $mv_string=%concat(<font color='yellow'>,@mv_curr,</font>,"/",@mv_max,<font color='dark gray'>,mv,</font>)
}
#IF ((@mv_curr/@mv_max)<0.50)
{
 $mv_string=%concat(<font color='red'>,@mv_curr,</font>,"/",@mv_max,<font color='dark gray'>,mv,</font>)
}

#IF (@combat=1)
{
 #WRITELOG " "
 #WRITELOG > @Time | $hp_string | $mana_string |$mv_String
 #WRITELOG " "
}
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
intoK
Apprentice


Joined: 18 Feb 2007
Posts: 190

PostPosted: Tue Nov 04, 2008 10:59 pm   
 
have you actually tried checking output of those functions? this is basics of debugging
try, #SA %concat(<font color='red'>,@mv_curr,</font>,"/",@mv_max,<font color='dark gray'>,mv,</font>)
see if you can figure out what you doing wrong
edit: sorry, this wont work due to mxp :P but you should still be able to figure out, check what is written to log in raw form
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Tue Nov 04, 2008 11:16 pm   
 
So what am I supposed to do? I have no clue why my spaces get eaten by everything. It's a major problem and I hate it, but I havent ever been able to solve it. One of my aliases is hurt by it too...

Code:


ID: fireproof
#IF (%1=1)
{
 remove '%-2'
 c fireproof '%-2'
 wear '%-2'
}
#IF (%1=2)
{
 remove 2.'%-2'
 c fireproof '%-2'
 wear '%-2'
 remove '%-2'
 c fireproof '%-2'
 wear '%-2'
}


I can't do
fireproof 2 amulet austinian

because it eats the space. How can I fix what I don't know?
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
intoK
Apprentice


Joined: 18 Feb 2007
Posts: 190

PostPosted: Tue Nov 04, 2008 11:32 pm   
 
use quotes when there are spaces ie. "<font color='red'>"

im not sure what your alias its supposed to do, but it seems to be working fine

Code:
>fp 2 abc def
remove 2.'abc def'
c fireproof 'abc def'
wear 'abc def'
remove 'abc def'
c fireproof 'abc def'
wear 'abc def'
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Tue Nov 04, 2008 11:38 pm   
 
Alright. Apparently the default background is white and text is black, I hope there's an option in there to change that too... *sighs*

Edit:
Heh, they're ALL Colored red. Usually that means the logical statement has a problem, usually a slight mistake that catches everything.

Code:

#IF (((@mv_curr/@mv_max)<0.75) AND ((@mv_curr/@mv_max)>=0.50))


So far as I know, that logical statement should work. Turn it yellow if it's less than 75 and more than 50

Code:

((@mv_curr/@mv_max)<0.50)


If it is less than 50, and only if it is less, then it is red. Now it would seem to me that the problem would be here.?



That's .88 and yet it doesn't stay white, it goes to red which should only tact on under .50, this so confusing, it seemed simple at first but these little details are killing me.

Edit:

NOTE: If I take the html file and specifically save it as a .html (via the options, not the .htm) then the background and foreground color remains true to the MUD. However logging in html doesn't?
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
intoK
Apprentice


Joined: 18 Feb 2007
Posts: 190

PostPosted: Wed Nov 05, 2008 12:46 am   
 
idk wo looking in it, and your code is so bulky and ugly i dont wanna see it again Razz , try this

Code:
#GAGLOG
#IF @combat {
 $hpp = @hp_curr/@hp_max
 $mnp = @mana_curr/@mana_max
 $mvp = @mv_curr/@mv_max
 #WRITELOG <br/>> %time(hh:nna/p"m") | <font color='%switch($hpp<0.5,"red",$hpp<0.75,"yellow",1,"white")'>@hp_curr</font>/@hp_max<font color='red'>hp</font> | <font color='%switch($mnp<0.5,"red",$mnp<0.75,"yellow",1,"white")'>@mana_curr</font>/@mana_max<font color='blue'>mn</font> | <font color='%switch($mvp<0.5,"red",$mvp<0.75,"yellow",1,"white")'>@mv_curr</font>/@mv_max<font color='dark gray'>mv</font><br/>
}
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Wed Nov 05, 2008 1:15 am   
 
But... that code is one giant blob, there's no pretty formatting!
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Wed Nov 05, 2008 1:36 am   
 
I adjusted it a little to fit with its purpose and one style pref. @time is actually ingame time and so it needs to be @time. In any case, it instantly goes to read once it's a value below 1. Looking at your code it looks like it will only be white if it's equal to 1, though it should be white from .75-1, and it should be yellow after that, not red. So I'm confused as to what to do.

Code:

#GAGLOG
#IF @combat {
 $hpp = @hp_curr/@hp_max
 $mnp = @mana_curr/@mana_max
 $mvp = @mv_curr/@mv_max
 #WRITELOG <br/>> @time | <font color='%switch($hpp<0.5,"red",$hpp<0.75,"yellow",1,"white")'>@hp_curr</font>/<font color='white'>@hp_max</font><font color='red'>hp</font> | <font color='%switch($mnp<0.5,"red",$mnp<0.75,"yellow",1,"white")'>@mana_curr</font>/<font color='white'>@mana_max</font><font color='blue'>mn</font> | <font color='%switch($mvp<0.5,"red",$mvp<0.75,"yellow",1,"white")'>@mv_curr</font>/<font color='white'>@mv_max</font><font color='dark gray'>mv</font><br/>
}


Also, oddly enough, mv just doesn't show up at all.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Wed Nov 05, 2008 1:41 am   
 
Perhaps it should be...

Code:

<font color='%switch($hpp<0.5,"red",$hpp<0.75,"yellow",$hpp>0.75,"white")'>


??
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
mr_kent
Enchanter


Joined: 10 Oct 2000
Posts: 698

PostPosted: Wed Nov 05, 2008 8:15 am   
 
Do what you like, but the code as given is correct. The %switch function tests each value until it evaluates as true. Since '1' evaluates as TRUE, the last color ('white') becomes the default value if neither of the first two are true. From the CMUD manual.
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Wed Nov 05, 2008 12:09 pm   
 
Alright. Doesn't explain why it immediately goes to red when it's less than 100% though. :/
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
intoK
Apprentice


Joined: 18 Feb 2007
Posts: 190

PostPosted: Wed Nov 05, 2008 1:30 pm   
 
because there is no floating point conversion i told you about earlier Confused

$hpp = @hp_curr/%float(@hp_max)
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Wed Nov 05, 2008 2:57 pm   
 
Oh, I did forget about that entirely. Let me adjust and I'll get back to you, thanks.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Wed Nov 05, 2008 3:27 pm   
 
It works wonderfully, thank you. I feel like I certainly learned some things from that and will be working to make it bigger and better!
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
intoK
Apprentice


Joined: 18 Feb 2007
Posts: 190

PostPosted: Wed Nov 05, 2008 5:16 pm   
 
np, i certainly hope you did
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Wed Nov 05, 2008 6:12 pm   
 
Well, now I know why it's been "eating" my spaces, that I need to use html with my new html logging methods, as opposed to ANSI. I know a bit more about concat and the %switch() and %if() functions as well as how to nest them in other elements for dynamic effects.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion 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