Multiple "Select Case spell" off one Sub routine

Posted by Natasi on Mon 18 Oct 2004 09:00 AM — 20 posts, 72,783 views.

#0
Ok, I'm trying to set up a balance that is called off one trigger and seperates the Salve and Herb healing so that it will cure only ONE salve affliction and ONE herb affliction. I think I have the basics down and have listed what I've done.


Sub Diagcheck (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
End If
Next
For Each v In world.GetVariableList
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

So, let's say, I'm trying to get "herbone" and "salveone" to be cured while even if the others need to be cured aswell, but need to wait. Thanks for any help you guys can give!

#1
Another wya I can think of this working is if the trigger could call more than one sub routine. Is that possible?
USA #2
Just make a subroutine, and then call it.

If you want to do it from inside that sub, just make another one, such as:

NewSub(anything you want to pass to it)
Stuff
End Sub

and then call it from inside that other sub by calling:

NewSub(the stuff you pass)

#3
So, it would look like this then? I'm still new to these sub routines, sorry.

Sub Diagcheck (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
End If
Next
Sub Diagcheck2 (a, b, c)
For Each v In world.GetVariableList
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
USA #4
No, you have a subroutine in a subroutine, they are seperate entities.

Sub DiagCheck (a,b,c) 'this is called from MC
'Stuff to do in this sub
Routine1 (height,width) 'we are calling the other sub, we COULD type "call routine1 (height,width)" but the call can be omitted.
End Sub

Sub Routine1 (height, width) 'this is a sub called on its own.
send "the area is " & height * width
end sub

If you have the script reference (Windows Scripting Host help file), which is linked to if you go to the mushclient forums, then the Script functions, then script engines you can download, its the third one, you can search "sub" and call and such.
Amended on Mon 18 Oct 2004 08:06 PM by Flannel
#5
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
USA #6
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".
#7
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
USA #8
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.
#9
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.
USA #10
I guess Im just not following. Whats the problem?

Isnt it the same code in both routines?
#11
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
Amended on Tue 19 Oct 2004 01:36 AM by Nick Gammon
Australia Forum Administrator #12
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?
#13
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
USA #14
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)
Australia Forum Administrator #15
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.

#16
Thank you for the help Flannel and Nick. This has helped me understand alot more and it works now.
#17
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?
Australia Forum Administrator #18
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.
#19
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!