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

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Tips and tricks
. . -> [Subject]  Multiple "Select Case spell" off one Sub routine

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Multiple "Select Case spell" off one Sub routine
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please)
Maximum of 6000 characters. Text only please, no HTML.
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1 2  

Posted by Gore   (207 posts)  [Biography] bio
Date Wed 01 Dec 2004 04:08 PM (UTC)  quote  ]

Amended on Wed 01 Dec 2004 04:09 PM (UTC) by Gore

Message
Although this is an old post.. figured I might put my 2 cents in and try and suggest an easier way for you, Natasi (if, you ever ready this post hehe)

What you might want to try, because when you are healing completely via script, is to keep all your variables scripted, instead of client side variables.

For instance,



Dim aeon
Dim paralyse

Sub Aeon_Log (name, output, wildcard)
  aeon = 1     ' 1 = true, which means you have aeon
End Sub

Sub Aeon_cure (name, output, wildcard)
  aeon = 0     ' 0 = false, which means you don't have aeon
End Sub

Sub Paralyse_Log (name, output, wildcard)
  paralyse = 1
End Sub

Sub Paralyse_Cure (name, output, wildcard)
  paralyse = 0
End Sub

Sub Heal_me (name, output, wildcard)
  If aeon = 1 then             ' if you have aeon then..
    World.send "smoke pipe"    ' to cure aeon
  Elseif paralyse = 1 then     ' If you don't have aeon,
                               ' but have paralysis then:
    World.Send "eat bloodroot" ' to cure paralyse
  End If
End Sub


In my opinion, a lot better, or atleast easier to understand than case statements.

I may be wrong though!
[Go to top] top

Posted by Nick Gammon   Australia  (18,797 posts)  [Biography] bio   Forum Administrator
Date Sun 24 Oct 2004 10:17 PM (UTC)  quote  ]
Message
There is no way to stop a script once it starts, control is handed over to the script engine (eg. VBscript). The only way is to code so that loops don't happen.

Once properly debugged this shouldn't be happening to you, after all, every loop in a script should have a way to terminate. If there is a place you can't otherwise work out how to do it, you could try this:



counter = 0
while (some condition) 

  ' blah blah - do things here

  counter = counter + 1
  if counter > 1000 then exit sub

wend


But you are really better off looking at where it is happening and stopping the real problem.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Natasi   (79 posts)  [Biography] bio
Date Sun 24 Oct 2004 06:53 PM (UTC)  quote  ]
Message
I have everything working now but every so often, like if a Sub gets looped somehow and I end up repeating the same action alot, the client freezes up on me and kicks me from the realm. Is there a way to stop this?
[Go to top] top

Posted by Natasi   (79 posts)  [Biography] bio
Date Tue 19 Oct 2004 03:05 PM (UTC)  quote  ]
Message
Thank you for the help Flannel and Nick. This has helped me understand alot more and it works now.
[Go to top] top

Posted by Nick Gammon   Australia  (18,797 posts)  [Biography] bio   Forum Administrator
Date Tue 19 Oct 2004 06:20 AM (UTC)  quote  ]
Message
OK, but this looks far too complicated:


For Each v In world.GetVariableList
  value = world.GetVariable (v)
  If Left (v, 11) = "affliction_" Then
   spell = Mid (v, 12)
   If value = "on" Then
     Select Case spell 
       Case "herbone" world.sendpush "***TESTone***"
       Case "herbtwo" world.sendpush "***TESTtwo***"
End Select
Exit Sub
End If
end if
next


You are looping through all variables, just looking for two exact ones. It would be a lot shorter and easier to read to do this:


if GetVariable ("affliction_herbone") = "on" Then
  send "TestOne"
end if

if GetVariable ("affliction_herbtwo") = "on" Then
  send "TestTwo"
end if


And, you don't need two subs to do two things, just do two things in the one sub.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Tue 19 Oct 2004 04:36 AM (UTC)  quote  ]
Message
You can call two subs from the same trigger.

Send to: Script
and then call them just like you called routine1.

So your send text would be:
call routine1 (stuff)
call routine2 (stuff)

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by Natasi   (79 posts)  [Biography] bio
Date Tue 19 Oct 2004 03:04 AM (UTC)  quote  ]
Message
I'm trying to set a call for when I use DIAG to check my afflictions. The thing though is I am using the "You are:" to send a reset clearing all affliction variables to off then the afflictions listed under the "You are:" will turn their respective variables back to on and then when I recover equilibrium a call will be sent to the Sub Herbhealing so it can start curing the afflictions.

The reason I have two Sub routines is because I need to have different afflictions covered so that I can maintain HERB and SALVE balance. If I can call multiple Subs from just one triggerthat would be best, but I can't as far as I know.

The second part checking Aeon was a mistake, it wasn't supposed to be there
[Go to top] top

Posted by Nick Gammon   Australia  (18,797 posts)  [Biography] bio   Forum Administrator
Date Tue 19 Oct 2004 01:42 AM (UTC)  quote  ]
Message
I've added [code] to your post to show the indenting, which unforunately is not very much.

It is much easier to read if you indent things like ifs, like this:


If anorexia = "on" Then
  exit sub
end if


It isn't clear what you are trying to do here. You have two virtually identical subs, and one calls the other. Why do that?

Are you thinking about what the code is doing? For instance, in the herbhealing sub you have the above test (if anorexia = "on") and if it is "on" then you exit the sub. Thus you will never call routine1, but in routine1 you also test if anorexia is on. Why?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Natasi   (79 posts)  [Biography] bio
Date Mon 18 Oct 2004 09:46 PM (UTC)  quote  ]

Amended on Tue 19 Oct 2004 01:36 AM (UTC) by Nick Gammon

Message
Ok, saying the in my variables section I have "herbone" "on", "herbtwo" "on", "salveone" "on", "salvetwo" "off".
Now, In order to seperate Herb and Salve balance I need this Sub to cure one of the "herb" afflictions and one of the "salve" afflictions, but ONLY one of each. Seeing as how the variables are set I currently have 2 herb afflictions and one salve. After calling the Sub I should cure one of each elaving me with one herb affliction after.
With the way I have the sub now it only cures one of the herb afflictions and doesn't even seem to notice the salve afflictions. Here is the last Sub as I had it


Sub herbhealing (a, b, c)
Dim value, spell, anorexia, aeon
anorexia = world.getvariable ("affliction_anorexia")
aeon = world.getvariable ("affliction_aeon")
If aeon = "on" Then
Exit Sub
end if
If anorexia = "on" Then
exit sub
end if
For Each v In world.GetVariableList
  value = world.GetVariable (v)
  If Left (v, 11) = "affliction_" Then
   spell = Mid (v, 12)
   If value = "on" Then
     Select Case spell 
       Case "herbone" world.sendpush "***TESTone***"
       Case "herbtwo" world.sendpush "***TESTtwo***"
End Select
Exit Sub
End If
end if
next
routine1 a, b, c
end sub

Sub routine1 (a, b, c)
Dim value, spell, anorexia, aeon
anorexia = world.getvariable ("affliction_anorexia")
aeon = world.getvariable ("affliction_aeon")
If aeon = "on" Then
Exit Sub
end if
If anorexia = "on" Then
exit sub
end if
For Each v In world.GetVariableList
value = world.GetVariable (v)
If Left (v, 11) = "affliction_" Then
spell = Mid (v, 12)
If value = "on" Then
Select Case spell 
Case "salveone" world.sendpush "***TESTthree***"
Case "salvetwo" world.sendpush "***TESTfour***"
End Select
Exit Sub
End If
end if
next
end sub


Again, I'm sorry for any irritation this may have caused
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Mon 18 Oct 2004 09:34 PM (UTC)  quote  ]
Message
I guess Im just not following. Whats the problem?

Isnt it the same code in both routines?

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by Natasi   (79 posts)  [Biography] bio
Date Mon 18 Oct 2004 09:11 PM (UTC)  quote  ]
Message
ok, I'm not getting errors anymore. When the variable for an affliction in the Sub Herbhealing is on then it trys to cure it, which is good. Now, when I have an affliction in the Sub Routine1 area "on" then nothing is cured, nothing from the Herbhealing or Routine1 sub cure.
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Mon 18 Oct 2004 09:02 PM (UTC)  quote  ]
Message
Ah.
When you use call, you use parenthesis, when you dont use call, you omit the parenthesis:

Call MyProc(firstarg, secondarg)
MyProc firstarg, secondarg

Do the exact same thing.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by Natasi   (79 posts)  [Biography] bio
Date Mon 18 Oct 2004 08:59 PM (UTC)  quote  ]
Message
Error number: -2146827244
Event: Execution of line 70 column 19
Description: Cannot use parentheses when calling a Sub
Line in error:
routine1 (a, b, c)
Called by: Immediate execution

That what I keep getting when putting that before the end sub part
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Mon 18 Oct 2004 08:54 PM (UTC)  quote  ]
Message
You need to put in three arguements. Since thats what it's expecting. (its 'expecting' the name, the line, and an array of wildcards, but it could be any three arguements).

and in your subroutine called routine1, you mistyped. Youre calling "routine1" but your sub is named "rountine1".

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by Natasi   (79 posts)  [Biography] bio
Date Mon 18 Oct 2004 08:41 PM (UTC)  quote  ]
Message
Thanks for the help so far Flannel, I dl'd the file and I'm going through it, but there's alot there to learn. I made another attempt and either I'm missing the point or I'm think headed but I still can't get it to work. This is what I'm at now...I have the Sub called from MC and at the end the CALL Routine1....*it wouldn't let me put in ()*

Sub herbhealing (a, b, c)
Dim value, spell, anorexia, aeon
anorexia = world.getvariable ("affliction_anorexia")
aeon = world.getvariable ("affliction_aeon")
If aeon = "on" Then
Exit Sub
end if
If anorexia = "on" Then
exit sub
end if
For Each v In world.GetVariableList
value = world.GetVariable (v)
If Left (v, 11) = "affliction_" Then
spell = Mid (v, 12)
If value = "on" Then
Select Case spell
Case "stupidity" world.sendpush "***TESTSTUPID***"
Case "slickness" world.sendpush "***TESTSLICK***"
End Select
Exit Sub
End If
end if
next
routine1
end sub

Sub rountine1 (a, b, c)
Dim value, spell, anorexia, aeon
anorexia = world.getvariable ("affliction_anorexia")
aeon = world.getvariable ("affliction_aeon")
If aeon = "on" Then
Exit Sub
end if
If anorexia = "on" Then
exit sub
end if
For Each v In world.GetVariableList
value = world.GetVariable (v)
If Left (v, 11) = "affliction_" Then
spell = Mid (v, 12)
If value = "on" Then
Select Case spell
Case "stupidity" world.sendpush "***TESTSTUPID***"
End Select
Exit Sub
End If
end if
next
end sub
[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.


7,484 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]