function trouble

Posted by Ishnaf on Thu 24 Apr 2003 09:07 AM — 5 posts, 24,038 views.

Australia #0
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..
Australia Forum Administrator #1
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.

Amended on Thu 24 Apr 2003 11:37 AM by Nick Gammon
#2
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).

Amended on Thu 24 Apr 2003 01:57 PM by Vaejor
USA #3
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
Amended on Tue 28 Oct 2003 09:52 AM by Norbert
Australia Forum Administrator #4
Rather than use space as a monster name separator, use something that won't be in their name, like a comma.