[Home] [Downloads] [Search] [Help/forum]


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, 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 ➜ Tips and tricks ➜ Making my Script respond faster.

Making my Script respond faster.

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


Posted by Natasi   (79 posts)  Bio
Date Thu 03 Mar 2005 05:23 PM (UTC)
Message
Ok, I've got over 5k lines of code in my script and I'm looking to redo the entire thing so it will run smoother. I've been getting help and know a few things I need to change already and it was suggested to use Arrays, but those are just insanely confusing so far. Any tips on a smoother/faster way to write the script would be great. I use VBscript and below is an example of how I have my script.

******************************************************
Sub Diagpurgheal (a, b, c)
if getvariable ("affliction_aeonD") = "1" then
exit sub
end if
if getvariable ("affliction_slicknessD") = "1" then
exit sub
end if
if getvariable ("affliction_crotamineD") = "1" then
world.sendpush "drink antidote"
exit sub
end if
if getvariable ("affliction_asthmaD") = "1" then
world.sendpush "drink melancholic"
exit sub
end if
if getvariable ("affliction_vomitingD") = "1" then
world.sendpush "drink choleric"
exit sub
end if
end sub

**************************************************

Like Flannel pointed out that instead of "world.sendpush, I should have just "send". Anything like that is appreciated.
Top

Posted by Tsunami   USA  (204 posts)  Bio
Date Reply #1 on Thu 03 Mar 2005 06:30 PM (UTC)
Message
Well, my personal preference in auto-healers like this is not to operate directly on MC variables, but on VBScript variables. TO be honest, I don't know for sure that this is faster, but it would seem to me that it should be. However, if you need to use a hastbale/associative array type structure for some other reason, this doesn't really work. I suppose you could maybe use the Dictionary class or something, but that's beyond my knowledge.
Top

Posted by Natasi   (79 posts)  Bio
Date Reply #2 on Thu 03 Mar 2005 10:22 PM (UTC)
Message
VBscript Variables? would you mind giving an example of how that would look/work?
Top

Posted by Tsunami   USA  (204 posts)  Bio
Date Reply #3 on Fri 04 Mar 2005 02:49 PM (UTC)
Message
Well, instead of using:

getvariable ("affliction_aeonD") = "1"


you could declare the variable:

dim affliction_aeonD


initialize when the plugin loads:

sub OnPluginInstall()
  affliction_aeonD = cbool(getVariable("afflcition_aeonD"))
end sub


and use that variable:

if affliction_aeonD = vbTrue then
  ...
end if


and then save it at the end:

sub OnPluginSaveState()
  setVariable("affliction_aeonD",affliction_aeonD)
end sub
[\code]

hope that helps
Top

Posted by Natasi   (79 posts)  Bio
Date Reply #4 on Fri 04 Mar 2005 07:17 PM (UTC)
Message
The variables are in an ever changing state though. I heard that VBscript variables wouldn't work in such a situation
Top

Posted by Tsunami   USA  (204 posts)  Bio
Date Reply #5 on Sat 05 Mar 2005 02:03 PM (UTC)
Message
I'm not quite sure what you mean, as the definition of a variable in any language is to hold a value that may change, unless you declare it (in Java for example)
final
.

Of course you can change the value of a VBScript variable whenever you want.

dim v
v = "hello"
v = v & " Tim"
etc...

The MushClient variables will not be changing unless you tell them to do so either. If you have another plugin that affects this plugin's variables, in which case you must know the plugins unique id, then you might have a problem. However, I doubt that this is the case.
Top

Posted by BBAlpha   (10 posts)  Bio
Date Reply #6 on Sun 06 Mar 2005 04:36 PM (UTC)

Amended on Sun 06 Mar 2005 04:57 PM (UTC) by BBAlpha

Message
After you initialize your variables in script as indicated above, you'd call a general catchall sub in your script with the appropriate triggers. Since I'm familiar with the application you're working on, we'll call this:


Sub AfflictOn(a,b,c)

DoCures()

End Sub


Name your trigger, for example:

Trigger: "your movement through the time stream is slowed."

The name of that trigger could be "Aeon1".

Within the affliction catch sub, we'd then do a simple check.


Sub AfflictOn(a,b,c)
If a = "Aeon1" Then
  affliction_aeon = vbTrue
Endif

DoCures()

End Sub


However, since you've got tons of these you'll be checking, use a Select statement instead of multiple Ifs. You'll pick up some speed there.

Now, whenever you get hit with your various affliction triggers, you'll call this Sub which will set the VBScript variable. Since that information only has to be passed once (per trigger hit) rather than making a callback to MC for every logic check, this will improve your speed nicely. Simply put, we're reducing the number of times that information has to get from MC to the script (getvariable).

You would do the same for cures, too.


Sub AfflictOff(a,b,c)
If a = "AeonCure1" Then
  affliction_aeon = vbFalse
Endif
End Sub


Pardon if the code is poor, it's been a while since I've dealt with VBScript. I'm pretty sure it's clean, though.
Top

Posted by Nick Gammon   Australia  (23,046 posts)  Bio   Forum Administrator
Date Reply #7 on Wed 23 Mar 2005 08:52 PM (UTC)
Message
Quote:

The variables are in an ever changing state though. I heard that VBscript variables wouldn't work in such a situation


Variables which are *outside* a sub or function should retain their value for that session. You would need to initialise them (if necessary) when the script loads, and save them (say) at world close time.

You might consider using Lua, I did an example a while ago in the Lua section which shows how you can use a Lua variable to automatically get/put from MUSHclient variables with a lot less fiddling around, although "under the hood" it does the same thing, so it doesn't save time, it just looks neater.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Larkin   (278 posts)  Bio
Date Reply #8 on Thu 31 Mar 2005 01:37 PM (UTC)
Message
The best part about that little script, Nick, is the layer of abstraction it provides for my scripts. I tweaked it a little bit to return a number when it's a number, or true/false when it's a boolean keyword. I didn't have to change dozens of lines of code throughout my scripts. I simply changed the variable table script and everything that relies on it was automatically fixed. I love a good, clean interface (though my code can sometimes get messy and complex)...
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #9 on Thu 31 Mar 2005 05:39 PM (UTC)

Amended on Thu 31 Mar 2005 05:42 PM (UTC) by Flannel

Message
I've done a similar thing for variable management (in VBScript).
(I've already posted it in another thread, but since this was what it was designed for (and for Natasi too, for that matter), it makes sense to post here, just a straight copy and paste):

I've written a script that handles working with MCVariables as script variables (and specifically tailored to working with an array of related variables, a set of afflictions in this case, but it really could be anything, they could be as related as belonging to the same character, which would provide the same as Nick's table thing in lua, except it doesn't update to the world automatically).
You can download it here:
http://mud.bussett.com/arrays.zip

Documentation is in the script file, and the world file that comes with it shows a couple of examples (check the aliases) which basically do what you need. You can also email me and ask (emails at the top of the script file) about whatever.
It basically allows for arrays to be used (without being much more complicated than storing a value per affect, or spells, or defense in this case) as associative arrays (or a set of three arrays to be used as complete listings, see the aliases) since VBScript doesn't do associative arrays. As well as providing subroutines to save the values to MCVariables at connect/disconnect or whatever.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Nexes   (65 posts)  Bio
Date Reply #10 on Wed 18 May 2005 07:43 AM (UTC)

Amended on Thu 19 May 2005 07:36 PM (UTC) by Nexes

Message
Oh! Flannel, your script looks just like what I need (Something like a java ArrayList or a ZMud List where you can add stuff, get rid of stuff at arbitrary locations, ect) but its in VB and I don't think Mushclient can run scipts from two languages at the same time. Any chance you could translate it into javascript for me? *grin* Guess its too much to hope for, so instead could you point me to any javascript equivalents if they exist?

EDIT: Actually I don't need this any more, someone has informed me that SQL does what I want and I realized I can use that in Mushclient.
Top

Posted by Larkin   (278 posts)  Bio
Date Reply #11 on Thu 19 May 2005 07:38 PM (UTC)
Message
If you make use of plugins, you can use a separate language in each plugin. One could use VBscript, another Python, and another one could use PerlScript.
Top

Posted by Nexes   (65 posts)  Bio
Date Reply #12 on Fri 20 May 2005 06:08 AM (UTC)

Amended on Fri 20 May 2005 06:10 AM (UTC) by Nexes

Message
I guess I could try doing that, but then if I wanted to make any modifications I'd be in trouble since I can't read VB.
Top

Posted by Larkin   (278 posts)  Bio
Date Reply #13 on Fri 20 May 2005 07:02 PM (UTC)
Message
In my experience, learning one language well makes it very easy to learn other languages at least enough to know basically what they're doing. They've got similar constructs at the lower level, like conditional statements, looping commands, etc. Some will do classes, inline functions, or other more advanced things, but you can generally find a way to relate the language to something else you already know.

VBscript isn't so different in its syntax from Python, JavaScript, or Lua that you couldn't figure it out with maybe a little bit of help from others here.
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.


38,643 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

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]