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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  VBscript
. . -> [Subject]  function trouble

function trouble

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


Posted by Ishnaf   Australia  (17 posts)  [Biography] 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!
[Go to top] top

Posted by Nick Gammon   Australia  (22,982 posts)  [Biography] 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
[Go to top] top

Posted by Vaejor   (120 posts)  [Biography] 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).

[Go to top] top

Posted by Norbert   USA  (61 posts)  [Biography] 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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,982 posts)  [Biography] 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
[Go to top] 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.


17,129 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] 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]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]