All right... Why doesn't this work?

Posted by David B on Fri 29 Aug 2003 10:00 PM — 10 posts, 34,476 views.

USA #0
dim XPOLD, XPNEW, XPDIFF
world.setvariable "XPNEW", "%1"
XPOLD = CInt(world.getvariable ("XPOLD"))
XPNEW = CInt(world.getvariable ("XPNEW"))
XPDIFF = (XPOLD - XPNEW)
if XPDIFF < 0 then
 XPDIFF = (XPDIFF + 100)
elseif XPDIFF = 0 then
exit sub
end if
world.setvariable ("XPOLD"), XPNEW
world.setvariable "XPDIFF", XPDIFF
world.enabletrigger "XP", FALSE



This of course is a trigger that is sent to script...
It doesn't work, Why? Can you make it so that it does work in the future?

As you know from my recent posts I'm writting an infobar script for the mud I play, Right now its only checking the prompt when I kill a creature, I'd like to have it check on EVERY prompt, but if the difference is 0 I want it to ignore the rest of the script. I take it that this is one of those few things that just can't be done in this fashion.
Amended on Fri 29 Aug 2003 10:01 PM by David B
USA #1
Umm. One good guess would be this line:

world.setvariable ("XPOLD"), XPNEW

You don't need the () and I am actually surprised you don't get an error of some kind. If it is some other issue, then I have no idea.
Australia Forum Administrator #2
There are two ways you could re-work this. One is to rejig the "if", like this:


dim XPOLD, XPNEW, XPDIFF
world.setvariable "XPNEW", "%1"
XPOLD = CInt(world.getvariable ("XPOLD"))
XPNEW = CInt(world.getvariable ("XPNEW"))
XPDIFF = (XPOLD - XPNEW)
if XPDIFF < 0 then
 XPDIFF = (XPDIFF + 100)
elseif XPDIFF > 0 then
 world.setvariable ("XPOLD"), XPNEW
 world.setvariable "XPDIFF", XPDIFF
 world.enabletrigger "XP", FALSE
end if


The other is to put it into a sub after all, like was discussed here recently, eg.



sub mytrigger
dim XPOLD, XPNEW, XPDIFF
world.setvariable "XPNEW", "%1"
XPOLD = CInt(world.getvariable ("XPOLD"))
XPNEW = CInt(world.getvariable ("XPNEW"))
XPDIFF = (XPOLD - XPNEW)
if XPDIFF < 0 then
 XPDIFF = (XPDIFF + 100)
elseif XPDIFF = 0 then
exit sub
end if
world.setvariable ("XPOLD"), XPNEW
world.setvariable "XPDIFF", XPDIFF
world.enabletrigger "XP", FALSE
end sub

call mytrigger



That way you can "exit sub" because you have put it into one.

However the first approach is probably simpler.
USA #3
Thanks Nick the first one worked like a charm.

As for the whole ("VARIABLE") thing, I don't know, it works fine still. I fixed it just in case.

Finished Project:

world.infoclear
world.InfoFont "Arial", 13, 1
world.setvariable "EXPTOLEVEL", "%1"
world.setvariable "XPNEW", "%1"
dim EXPTICK, TICK, TICKERNEW, TICKERBLANK, EXPTOLEVEL, EXPFROMLEVEL, count
dim XPOLD, XPNEW, XPDIFF
XPOLD = CInt(world.getvariable ("XPOLD"))
XPNEW = CInt(world.getvariable ("XPNEW"))
XPDIFF = (XPOLD - XPNEW)
if XPDIFF < 0 then
XPDIFF = (XPDIFF + 100)
elseif XPDIFF > 0 then
world.setvariable "XPOLD", XPNEW
world.setvariable "XPDIFF", XPDIFF
world.enabletrigger "XP", FALSE
end if
EXPTOLEVEL = CInt(world.getvariable ("EXPTOLEVEL"))
EXPFROMLEVEL = (100 - EXPTOLEVEL)
world.setvariable "EXPFROMLEVEL", EXPFROMLEVEL
TICKERNEW = " "
TICKERBLANK = ""
TICK = "|"
EXPTICK = ""
 for count = 1 to CInt(world.getvariable ("EXPFROMLEVEL"))
  TICKERBLANK = (TICKERBLANK + TICKERNEW)
next
 for count = 1 to CInt(world.getvariable ("EXPTOLEVEL"))
  EXPTICK = (EXPTICK + TICK)
next
world.infoclear
world.InfoBackground "black"
world.InfoFont "Arial", 13, 1
world.infocolour "white"
world.info "Experience to Level ["
world.InfoColour "red"
world.info  EXPTICK
world.info TICKERBLANK
world.InfoColour "white"
world.info "] (" 
world.infocolour "yellow"
world.info world.getvariable ("EXPTOLEVEL")
world.infocolour "white"
world.info "%)   Last Gained (" 
world.infocolour "yellow"
world.info world.getvariable ("XPDIFF")
world.infocolour "white"
world.info "%)"


You guys have helped a lot.
More thanks to Nick for his Excellent Help files... Without them I'd have never been able to do this.
USA #4
Can you have Multiple lines on the Infobar?

Right now I have 1 line of Text.
Is it possible to put 2 lines, one on top of the other?


Experience |||||||||||||||||||
Hit Points |||||||||||||||
Australia Forum Administrator #5
No, you can't. However see my recent posting about a super info bar.

http://www.gammon.com.au/forum/?bbsubject_id=3128
USA #6
This should work, but it doesn't, Why?

world.infoclear
world.InfoBackground "black"
world.InfoFont "Arial", 12, 1
world.infocolour "white"
world.info "Experience To Level ["
if CInt(world.getvariable ("EXPTOLEVEL")) < 75 then
world.InfoColour "orange"
world.info  EXPTICK
elseif CInt(world.getvariable ("EXPTOLEVEL")) < 50 then
world.InfoColour "yellow"
world.info EXPTICK
elseif CInt(world.getvariable ("EXPTOLEVEL")) < 10 then
world.InfoColour "red"
world.info EXPTICK
else
world.infocolour "blue"
world.info EXPTICK
end if
world.info TICKERBLANK
world.InfoColour "white"
world.info "] (" 
world.infocolour "yellow"
world.info world.getvariable ("EXPTOLEVEL")
world.infocolour "white"
world.info "%)   Last Gained (" 
world.infocolour "yellow"
world.info world.getvariable ("XPDIFF")
world.infocolour "white"
world.info "%)    Current Level: "
world.infocolour "yellow"
world.info world.getvariable ("Level")


Thanks for the help
Australia Forum Administrator #7
Can you say in what way it doesn't work? Syntax error? If so, what and at what line? Something else? Please specify.
USA #8
if CInt(world.getvariable ("EXPTOLEVEL")) < 75 then
world.InfoColour "orange"
world.info  EXPTICK
elseif CInt(world.getvariable ("EXPTOLEVEL")) < 50 then
world.InfoColour "yellow"
world.info EXPTICK
elseif CInt(world.getvariable ("EXPTOLEVEL")) < 10 then
world.InfoColour "red"
world.info EXPTICK
else
world.infocolour "blue"
world.info EXPTICK
end if


It wouldn't cascade the way I wanted it too... I ended up figuring out that I had to reverse the order. so that it went 10, 25, 50, 75. Instead of 75, 50, 25, 10....

It didn't cross my mind at first to do it in reverse order.
50 is still less than 75 so it never checked 50 or 25 or 10.

My next issue here is this snippet:
dim levelold, level
levelold = CInt(world.getvariable ("level"))
level = (levelold + 1)
world.setvariable "level", level


That works fine and dandy, but once you go past level 100 you become a hero, and there is hero levels. Hero Level 1, 2, 3.... Up till hero level 750

Yes, a total of 850 levels or so... Once I hit 100 I'd like it to be able to say in the info bar Level: H1, H2, H3...

I hope that explains why that code didn't work, and I hope you can help me figure out how to make it so that this can count Hero levels.
USA #9
Never mind my last post, after talking to someone who codes He helped me figure it out:

dim levelold, level
levelold = CInt(world.getvariable ("level"))
if world.getvariable ("level2") = "subhero" then
level = (levelold + 1)
if level > 100 then
world.setvariable "level2", "H"
level = (level - 100)
world.setvariable "level", level
else
world.setvariable "level", level
end if
else
level = (levelold + 1)
world.setvariable "level", level
end if