Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ VBscript ➜ How would I condense this down in VBscript?

How would I condense this down in VBscript?

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by David Berthiaume   (202 posts)  Bio
Date Fri 15 Apr 2005 08:58 AM (UTC)

Amended on Fri 15 Apr 2005 09:00 AM (UTC) by David Berthiaume

Message
I already have a shortened Lua Version, I get the feeling there is some redundant code in this Script:

Edit: Matches on my prompt. I figured I wouldn't put the XML version of it, less confusing this way

^\<(.*)\%XTL\>$
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)
world.setvariable "XPOLD", XPNEW
world.setvariable "XPDIFF", XPDIFF
elseif XPDIFF > 0 then
world.setvariable "XPOLD", XPNEW
world.setvariable "XPDIFF", XPDIFF
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
dim space
space = " "
world.infoclear
world.InfoBackground "black"
world.InfoFont "Arial", 12, 1
world.infocolour "white"
world.info "("
if CInt(world.getvariable ("aaHP")) < 100 then
world.info space
world.infocolour "white"
world.info world.getvariable ("aaHP") & "%"
else
world.infocolour "white"
world.info world.getvariable ("aaHP") & "%"
end if
world.infocolour "red"
world.info "HP"
world.infocolour "white"
world.info "|"
if CInt(world.getvariable("aaMana")) < 100 then
world.info space
world.info world.getvariable ("aaMana")
else
world.info world.getvariable ("aaMana")
end if
world.info "%"
world.infocolour "olive"
world.info "Mana"
world.infocolour "white"
world.info "|" 
if CInt(world.getvariable ("aaMove")) < 100 then
world.info space
world.info world.getvariable ("aaMove")
else
world.info world.getvariable ("aaMove")
end if
world.info "%"
world.infocolour "darkcyan"
world.info "Move"
world.infocolour "white"
world.info ") ("
world.infocolour "lightgreen"
world.info world.getvariable ("aaHunger")
world.infocolour "white"
world.info ") "
world.info " ["
if CInt(world.getvariable ("EXPTOLEVEL")) < 5 then
world.InfoColour "red"
world.InfoFont "Arial", 12, 0
world.info EXPTICK
elseif CInt(world.getvariable ("EXPTOLEVEL")) < 10 then
world.InfoColour "lawngreen"
world.InfoFont "Arial", 12, 0
world.info EXPTICK
elseif CInt(world.getvariable ("EXPTOLEVEL")) < 20 then
world.InfoColour "green"
world.InfoFont "Arial", 12, 0
world.info EXPTICK
elseif CInt(world.getvariable ("EXPTOLEVEL")) < 30 then
world.InfoColour "darkorange"
world.InfoFont "Arial", 12, 0
world.info EXPTICK
elseif CInt(world.getvariable ("EXPTOLEVEL")) < 40 then
world.InfoColour "orange"
world.InfoFont "Arial", 12, 0
world.info EXPTICK
elseif CInt(world.getvariable ("EXPTOLEVEL")) < 50 then
world.InfoColour "goldenrod"
world.InfoFont "Arial", 12, 0
world.info EXPTICK
elseif CInt(world.getvariable ("EXPTOLEVEL")) < 60 then
world.InfoColour "gold"
world.InfoFont "Arial", 12, 0
world.info EXPTICK
elseif CInt(world.getvariable ("EXPTOLEVEL")) < 70 then
world.InfoColour "yellow"
world.InfoFont "Arial", 12, 0
world.info EXPTICK
elseif CInt(world.getvariable ("EXPTOLEVEL")) < 80 then
world.InfoColour "blue"
world.InfoFont "Arial", 12, 0
world.info EXPTICK
elseif CInt(world.getvariable ("EXPTOLEVEL")) < 90 then
world.InfoColour "mediumblue"
world.InfoFont "Arial", 12, 0
world.info EXPTICK
else
world.infocolour "purple"
world.InfoFont "Arial", 12, 0
world.info EXPTICK
end if
world.infocolour "black"
world.info TICKERBLANK
world.InfoColour "white"

world.InfoFont "Arial", 12, 1
world.info "] (" 
world.infocolour "yellow"
if CInt(world.getvariable ("EXPTOLEVEL")) < 100 then
world.info space
world.info world.getvariable ("EXPTOLEVEL")
else
world.info world.getvariable ("EXPTOLEVEL")
end if
world.infocolour "white"
world.info "%) "
InfoFont "Arial", 12, 1
Info "Last "
world.InfoFont "Arial", 12, 1
Info "(" 
world.InfoFont "Arial", 12, 1
world.infocolour "yellow"
world.info world.getvariable ("XPDIFF")
world.infocolour "white"
world.info "%) "
InfoFont "Arial", 12, 1
Info "Level: "
world.InfoFont "Arial", 12, 1
world.infocolour "yellow"
if world.getvariable ("CharacterInfoLevelStatus") = "subhero" then
world.info world.getvariable ("CharacterInfoLevel")
else
world.infocolour "red"
world.info world.getvariable ("CharacterInfoLevelStatus") & world.getvariable ("CharacterInfoLevel")
end if
InfoColour "white"
info " | "
InfoColour "green"
world.InfoFont "Arial", 12, 1
Info "Hero Points"
InfoColour "white"
Info ": "
InfoColour "red"
world.InfoFont "Arial", 12, 1
Info "@CharacterInfoCurrentHeroPoints"
world.EnableGroup "Highlighted Words", 0
Top

Posted by Poromenos   Greece  (1,037 posts)  Bio
Date Reply #1 on Fri 15 Apr 2005 12:46 PM (UTC)
Message
Indent, man! INDENT!

Aha, I will write a tool to indent VB scripts, I think...

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #2 on Fri 15 Apr 2005 02:44 PM (UTC)

Amended on Fri 15 Apr 2005 02:45 PM (UTC) by Flannel

Message
Anywhere that you do:

If XX Then
YY
ZZ
else
ZZ
end if

you can simply do:
If XX then
YY
endif
ZZ

And, get/setvariables take forever (relatively speaking), so when youre doing the cascade of exptolevel, try setting a VB Variable and checking against that (no matter how many times you check, you'll still only be using one getvariable).

And that whole section is 2/3s redundant (since you only need to set the colors in the if statements, and then you can set the font, and call the subroutine outside, afterwards).

Same thing here (although not as apparent):
if world.getvariable ("CharacterInfoLevelStatus") = "subhero" then
world.info world.getvariable ("CharacterInfoLevel")
else
world.infocolour "red"
world.info world.getvariable ("CharacterInfoLevelStatus") & world.getvariable ("CharacterInfoLevel")
end if

can become something like this:

if world.getvariable ("CharacterInfoLevelStatus") != "subhero" then
world.infocolour "red"
world.info world.getvariable ("CharacterInfoLevelStatus")
end if
world.info world.getvariable ("CharacterInfoLevel")
Of course, if the != subhero only is one other option, use an if statement not an if ! and change the test string.

And, are you using this inside of a trigger or not? Since at the very end you expand a variable, but then you don't for the rest of the thing.

Edit: Yep, you are. So why don't you expand variables instead of using getvariable? Not saying you should, just posing a question (as I have no idea of performance gain, if any).

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Poromenos   Greece  (1,037 posts)  Bio
Date Reply #3 on Fri 15 Apr 2005 06:40 PM (UTC)
Message
I did write that VBScript indenter, does anyone want it? It's in Python.

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #4 on Fri 15 Apr 2005 09:51 PM (UTC)
Message
Couldn't hurt to post it.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Poromenos   Greece  (1,037 posts)  Bio
Date Reply #5 on Sat 16 Apr 2005 09:53 AM (UTC)
Message

#######################################################################
# VBIndenter, script for indenting VBScript files.
# Copyright (C) 2005  Poromenos
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

import sys
from time import time
from shutil import move

INDENT_CHARACTERS = "    "

def fnParse(flInputFile, flOutputFile):
    """Parses the input file, indents lines accordingly and returns the parsed
    string."""
    intIndentationLevel = 0
    blnIndent = False

    for intLine, strLine in enumerate(flInputFile):
        lstLine = strLine.lower().split()
        if lstLine == []:
            pass
        elif lstLine[0] == "if" and lstLine[-1] != "then":
            pass
        elif lstLine[0] in ("if", "for", "sub", "function", "do", "with", "select"):
            blnIndent = True
        elif lstLine[0] in ("end", "next", "while"):
            intIndentationLevel -= 1
            if intIndentationLevel < 0:
                print("Warning: Indentation level is negative on line " + str(intLine) + ", check your code.")
        elif lstLine[0] in ("elseif", "else", "case"):
            intIndentationLevel -= 1
            blnIndent = True

        flOutputFile.write(INDENT_CHARACTERS * intIndentationLevel + strLine.strip() + "\n")

        if blnIndent:
            intIndentationLevel += 1
            blnIndent = False

def fnInitialise(strInputFilename, strOutputFilename = None):
    """Opens the input file, calls the parsing function and writes the indented
    file to the output."""
    if strOutputFilename == None:
        strOutputFilename = strInputFilename

    strTemporaryFilename = "v" + str(round(time())).replace(".","")[-8:-1] + ".tmp"

    try:
        flInput = file(strInputFilename)
        flOutput = file(strTemporaryFilename, "w+")
        print("Opened input file.")
    except IOError, (intError, strError):
        print("I/O error opening input file: %s" % (strError))
        sys.exit(1)

    print("Parsing...")
    fnParse(flInput, flOutput)
    flInput.close()
    flOutput.close()
    
    print("Writing...")
    move(strTemporaryFilename, strOutputFilename)
    print("Done!")

if len(sys.argv) == 2:
    fnInitialise(sys.argv[1])
elif len(sys.argv) == 3:
    fnInitialise(sys.argv[1], sys.argv[2])
else:
    print("Usage:\n\tVBIndent.py <input> [<output>]")


Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


21,989 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.