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
➜ function trouble
Posting of new messages is disabled at present.
Refresh page
Posted by
| Ishnaf
Australia (17 posts) Bio
|
Date
| Thu 24 Apr 2003 09:07 AM (UTC) |
Message
| gday, i was wondering if someone could give me a hand with my autoroller. I've got it working (its different to the plugin because i use a different mud), but i'd like to tidy it up, but im not quite sure how.
basically i want to set my arrays of values up in functions to make it neater and easier to change, e.g.:
function strength
Stre(1) =" Child"
Stre(2) =" Wimpy"
Stre(3) ="Pencil-neck"
Stre(4) =" Weak"
Stre(5) =" Pipsqueak"
end function
and then call this in my script:
sub autoroller(strName, strLine, aryWildcards)
dim stre
'some line to get & set stre array
'my code to check the value:
streVar = aryWildcards (1) 'this gets the rolled stat
streMin = world.getvariable ("StreMin") 'this gets the mimimum stat
dim streTmp 'this is a temp variable
for i=0 to 20
if streVar = stre(i) then
streTmp = i
world.setvariable "streTmp", streTmp
end if
next
'more code to check values and things....
end sub
basically all i need help with is:
'some line to get & set stre array
thanks a lot ppl.. |
egads! | Top |
|
Posted by
| Nick Gammon
Australia (23,122 posts) Bio
Forum Administrator |
Date
| Reply #1 on Thu 24 Apr 2003 11:36 AM (UTC) Amended on Thu 24 Apr 2003 11:37 AM (UTC) by Nick Gammon
|
Message
| Not quite sure what you mean, but a guide on accessing functions will probably help.
function strength (which)
dim Stre
Stre(1) = "Child"
Stre(2) = "Wimpy"
Stre(3) = "Pencil-neck"
Stre(4) = "Weak"
Stre(5) = "Pipsqueak"
if which >= 1 and which <= 5 then
strength = Stre (which)
else
strength = "<unknown>"
end if
end function
You need to pass down something (I presume) to the function, that is an argument in brackets. To return something you assign a value to the function name itself, as I have done.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Vaejor
(120 posts) Bio
|
Date
| Reply #2 on Thu 24 Apr 2003 01:56 PM (UTC) Amended on Thu 24 Apr 2003 01:57 PM (UTC) by Vaejor
|
Message
| If you would like a cleaner way to store your array, here is an idea.
VBScript has a Split() function which will take a string and split it into an array of strings. It will use whatever delimiter(s) you want to use as the seperators to determine how to split the string.
In this case, you could store all the data into a MushClient variable as such:
<variables>
<variable name="StreList"> Child
Wimpy
Pencil-neck
Weak
Pipsqueak</variable>
</variables>
Then when you wanted to access the data in here, you could simply do something like:
sub autoroller(strName, strLine, aryWildcards)
Dim Stre
Stre = Split(World.GetVariable("StreList"), vbCrLf)
....
end sub
This will pull the data from the MushClient variable "StreList", then split the data into an array using the carriage return/enter key (vbCrLf - although I seem to remember vbCr might be better to use, not sure why I still use the first...habit probably) as the delimiter. You should end up with an array very similiar to yours except that it will begin on (0) instead of (1).
| Top |
|
Posted by
| Norbert
USA (61 posts) Bio
|
Date
| Reply #3 on Mon 27 Oct 2003 12:13 PM (UTC) Amended on Tue 28 Oct 2003 09:52 AM (UTC) by Norbert
|
Message
| I'm having trouble with a function if anyone could help me out. I'm trying to make a list of worthy monsters, I have a trigger that catches the monster name, then I want to make sure it's not already in the list and if it's not in the list added it to the list and if it's already in the list to do nothing, this is what I have so far.
function searcha (arrayname, searchfor)
dim element
for each element in arrayname
if element = searchfor then
searcha = 1
Exit For
end if
Next
searcha = -1
end function
sub worthies(name, line, wildcards)
dim searchfor, array
world.setvariable "worthylist", " "
searchfor = wildcards (1)
array = split (world.getvariable ("worthylist"))
call searcha (array, searchfor)
if searcha = -1 then
array = array + " " + searchfor
world.setvariable "worthylist", array
end if
end sub
the problem right now is that monsters usually have 2 words in their names like 'Fire Giant'. When it gets sent to searcha there are too many elements. I was wondering if the dictionary thing in VB would be the best thing to do here or if there was some other way to get around this.
thank you
|
Norbert
-Do you know what it's like to fall in the mud and get kicked... in the head... with an iron boot?
Of course you don't, no one does. It never happens
It's a dumb question... skip it.
| Top |
|
Posted by
| Nick Gammon
Australia (23,122 posts) Bio
Forum Administrator |
Date
| Reply #4 on Sun 02 Nov 2003 07:56 PM (UTC) |
Message
| Rather than use space as a monster name separator, use something that won't be in their name, like a comma. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | 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.
18,512 views.
Posting of new messages is disabled at present.
Refresh page
top