Code Infobar

Posted by Halig on Fri 20 Feb 2015 09:41 AM — 9 posts, 32,193 views.

Portugal #0
Hi to all. What is wrong with this piece of code?
What i want is to show in the infobar, the vnum of the room that i'm in. I have everything working, but i can't make the colour to change. If the variable vnum is equal to 1205, then the text will be red, if the room is diferent, the colour will be blue.



InfoFont("FixedSys", 12, 0);
InfoColour("black");
Info("Sala: ");
if (room == 1205)
then
InfoColour ("red")
InfoFont("FixedSys", 12, 2)
Info(vnum)
else
InfoColour ("blue")
InfoFont("FixedSys", 12, 2)
Info(vnum)
end -- if

Thank you
USA #1
What exactly are you trying to match on?
Portugal #2
Hi. I'm trying to match the room vnum, in this case, 1205.
I already have a variable that changes when i change room. So i'm just trying to get the infobar showing when i'm in room 1205 it will be red, when i'm on any other room, it will be blue. I have that working, but in Jscript. I want this in lua. ;)
USA #3
What is the exact text you are trying to match? If you have it working in java, paste that here as well and the conversion should be simple enough.
Portugal #4
<aliases>
<alias
match="^-infobar(.*)"
enabled="y"
expand_variables="y"
regexp="y"
send_to="12"
keep_evaluating="y"
sequence="100"
>
<send>var cor; cor = "Blue"; //info font color
var back; back = "#D6D6D6"; //backgroud color
var other; other = "Red"; //other font color
var show;

if("%1"==" 0") show = 0;
else show = 1;

var wield;
var sanc;
arma_1 = world.getvariable("wield");
sanc = world.getvariable("sanc");

ShowInfoBar(0);
InfoClear();
InfoBackground(back);
InfoFont("FixedSys", 12, 0);InfoColour("Black");
Info("Wielded: ");
InfoFont("FixedSys", 12, 1);
if(wield == "nada") InfoColour(other); else InfoColour(cor);
Info(arma_1 + " ");

InfoFont("FixedSys", 12, 0);InfoColour("Black");
Info("Sanctuary: ");
InfoFont("FixedSys", 12, 1);
if(sanc == "on")InfoColour(cor);
else if(sanc == "off")InfoColour(other);
Info(sanc + " ");

ShowInfoBar(show);</send>
</alias>
</aliases>
Australia Forum Administrator #5
Variables from GetVariable are strings. In Lua strings and numbers compare differently. Try:


room = tonumber (room)
Portugal #6
Nick, i'm sorry, but i can't manage to figure where to put that in this code:


<aliases>
  <alias
   match="^-infobar"
   enabled="y"
   expand_variables="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>vnum = GetVariable("vnum")
wizi = GetVariable("wizi")
wield = GetVariable("wield")
players = GetVariable("players")
room = tonumber("vnum")

ShowInfoBar(False)
InfoClear()
InfoBackground("grey")

InfoFont("FixedSys", 12, 0)
InfoColour("black")
Info("Sala:")
if (room == 1205)
then
InfoColour ("red")
InfoFont("FixedSys", 12, 2)
Info(vnum)
else 
InfoColour ("blue")
InfoFont("FixedSys", 12, 2)
Info(vnum)
end -- if

InfoFont("FixedSys", 12, 0)
InfoColour("black")
Info("  Wizinvis:")
InfoFont("FixedSys", 12, 2)
InfoColour("blue")
Info(wizi)

InfoFont("FixedSys", 12, 0)
InfoColour("black")
Info("  Weapon:")
InfoFont("FixedSys", 12, 2)
InfoColour("blue")
Info(wield)

InfoFont("FixedSys", 12, 0)
InfoColour("black")
Info("  Horas:")
InfoFont("FixedSys", 12, 2)
InfoColour("blue")
Info(hours)

InfoFont("FixedSys", 12, 0)
InfoColour("black")
Info("  Players:")
InfoFont("FixedSys", 12, 2)
InfoColour("blue")
Info(players)

ShowInfoBar(true)</send>
  </alias>
</aliases>
Amended on Sat 21 Feb 2015 11:34 PM by Nick Gammon
Australia Forum Administrator #7

room = tonumber("vnum")


Yes, but the literal string "vnum" will never be 1205, right?

You need:


room = tonumber(vnum)
Amended on Sat 21 Feb 2015 11:42 PM by Nick Gammon
Portugal #8
Thank you Nick. It's working now :).