usage of 'or'

Posted by Neverwhere on Thu 26 Jun 2003 08:05 AM — 24 posts, 78,722 views.

USA #0
hrm, just a question, but does MUSH support 'or' in vb script? If not, whats the equivalent?

Ex:
if newhp = oldhp or newsp = oldsp then

Just wondering
USA #1
Yes, it does.
Mushclient loads the scripting engine, and lets it handle everything.

VBScript documentation is available, there's a link on this site, under the VBscript forum, at the top; and yes, its just standard VBscript syntax, Mushclient doesnt have its own version of VBscript.
Amended on Thu 26 Jun 2003 09:41 AM by Flannel
Canada #2
I think you need to put each expression in brackets, so try this syntax:

if (newhp = oldhp) or (newsp = oldsp) then
USA #3
Ok, I've tried both suggestions, and it still doesnt work. Myabe its just a script problem...

Sub OnNewHp(strAliasName, strOutput, arrWildCards)
newhp = world.getvariable ("newhp")
newsp = world.getvariable ("newsp")
oldsp = world.getvariable ("newsp")
oldhp = world.getvariable ("oldhp")
totalhp = world.getvariable ("totalhp")
totalsp = world.getvariable ("totalsp")
if (newhp = oldhp) or (newsp = oldsp) then
world.setvariable "oldhp",newhp
world.setvariable "oldsp",newsp
ElseIf (newhp <> oldhp) or (newsp <> oldsp) then
hpchange = newhp-oldhp
spchange = newsp-oldsp
if (hpchange < "0") or (spchange < "0") then
World.Send "ps Hp: "&newhp&"("&totalhp&") "&hpchange&" Sp: "&newsp&"("&totalsp&") "&spchange&""
ElseIf (hpchange >= "0") or (spchange >= "0") then
World.Send "ps Hp: "&newhp&"("&totalhp&") +"&hpchange&" Sp: "&newsp&"("&totalsp&") +"&spchange&""
End If
world.setvariable "oldhp",newhp
world.setvariable "oldsp",newsp
End If
End Sub

Any Suggestions? (yes, variables work correctly. The triggers firing get the required info for them, and I've checked and double checked them)
Amended on Sun 29 Jun 2003 07:24 AM by Neverwhere
Australia Forum Administrator #4
Can you clarify what the symptoms are? I am guessing it is not a syntax error, as you don't give a line number.

One possibility is the "string to number" issue. Variables are stored as strings, whereas you seem to be treating them as numbers. eg. something like this will not work as you expect ...


a = "22"
b = "123"

if  a < b then
  note "22 is less than 123"
else
  note "123 is less than 22"
end if


Since the first character of each string is different it will think that 123 is less than 22.

To fix this you need to convert to numbers, eg.

a = CInt ("22")
b = CInt ("123")

Similarly for your code.
Amended on Sun 29 Jun 2003 08:00 AM by Nick Gammon
USA #5
actually, there is no error report. The script runs fine, but it never proforms what it is supposed to ... it runs fine when i remove all the sp things, and i was just attempting to make it run when it has sp change also. I think its got something to do with the 'or''s but i could be wrong.

[Edit]
I know that the script goes to the first statement, because it processes the
world.setvariable "oldhp",newhp
world.setvariable "oldsp",newsp
from the very first if statment even if it is false (so im assuming thats where the error lies, within the first part of the if statment?)
Amended on Sun 29 Jun 2003 08:09 AM by Neverwhere
Australia Forum Administrator #6
I would still put the CInt into the getvariable lines, ie.

x = CInt (world.GetVariable ("Y"))

I think that will help. Also try showing what you actually get, eg.

hpchange = newhp-oldhp
spchange = newsp-oldsp

world.note "newhp = " & newhp
world.note "oldhp = " & oldhp
world.note "newsp = " & newsp
world.note "oldsp = " & oldsp
world.note "hpchange = " & hpchange
world.note "spchange = " & spchange
USA #7
ok, I think its official... Its far too late to be writing script....
Quote:

newsp = world.getvariable ("newsp")
oldsp = world.getvariable ("newsp")


Its time for bed .... (thanks Nick, Im sorry I cant think straight ;p)

Night :)
Australia Forum Administrator #8
Quote:

Myabe its just a script problem...


Well, you were right. The notes I suggested would have shown that up. VB can be strange but it doesn't usually do totally the wrong thing. :)
USA #9
aye, the notes helped out a lot. I was wondering why it was executing the change from newsp to oldsp even before it hit the if statment (thats where i stuck notes). Thanks again.

[Edit]

Acutally, will the CInt change the if statments? Meaning should i remove the "" around the zeros?
Amended on Sun 29 Jun 2003 08:31 AM by Neverwhere
Australia Forum Administrator #10
It would be logical if you are dealing in numbers to get rid of the quotes. VB will probably promote the string to an int, or the int to a string, but to be sure why not do it correctly yourself?
USA #11
Well, for one the MUD just went down for the next hour (rebooting) and im going to bed soon, which prohibits me from testing the script (unless there is a client-side tester?) and Im sure if I dont do it now, I wont remember in the morning. Sorry to bug you so much :/
USA #12
Ok, now I do have the correct variables in the script, but it still bugs... automatically executes the first if statement (i tried doing it with the CInt, and without, either way that 'or' forces it to do the first one for some reason, even tho the world.note's you gave me show that it does not equal zero)

[Without CInt]
if (hpchange = "0") or (spchange = "0") then
XXX
ElseIf (hpchange <> "0") or (spchange <> "0") then
XXX
End If

Is it the 'or' statements?
Australia Forum Administrator #13
Quote:

it does not equal zero


It? What does not equal zero? Your test is that:

if (hpchange = "0") or (spchange = "0") then


Are you saying that both hpchange and spchange are zero, yet it does the things after that if? Do you have world.notes to prove that?

Anyway, when I look at your earlier post, there is no such line.
Australia Forum Administrator #14
Let me give you a clue - there is no known fundamental bug in the way "or" works. Certainly not one that MUSHclient introduces, as it simply passes your script to the VBscript engine, and if VBscript can't do an "or" there would be thousands of programmers screaming.

Simply put in displays (world.note) after the test that you think should have passed/failed but didn't, to check what are passing to it. Remember, the line:

if A or B then

means it will pass the test if A is true or B is true. Thus, display A and B and see what is happening.
Amended on Sun 29 Jun 2003 10:03 AM by Nick Gammon
USA #15
Why are you even doing that second check?

wouldnt by definition, if the first one (the if theyre 0 check) wasnt true, the second one (if either is not 0) would be?

Just do an If Then Else, and ditch the second if.. since it seems redundant (unless of course, the hour is getting to me as well)
Australia Forum Administrator #16
Quote:

unless there is a client-side tester?


You can simulate MUD input (even when disconnected) with Shift+Ctrl+F12
USA #17
ACtually, (Now that Ive actually looked at the code) your first if, Shouldnt it be an AND?
You first check to see if EITHER of the variables is the same, and then you set both variables? (Why shouldnt you just do the one that is the same?)

THEN, you check (You only get here if neither of the variables are the same)
then, you find the change of each, and then check to see if the change is positive on one OR the other, and then check to see if its negative on one OR the other...

I think you should probably split it up to be something like this:

Check to see if sp is same, if it is, store new sp, check to see if hp is same, if it is, store new hp. Check to see if either of them have changed (OR) then, within that if have two sets of ifs, one for SP, then one for HP (or however youd like) to see if it (HP) changed (sicne we dont know which one of the two has) and then inside that, check if positive then since we know we wouldnt be this far if it was 0, we can do an else for negative, then step up a level, check the other (SP) has changed, then check for positive, and since we know again we wouldnt be here if its 0, we do an automatic negative. Then, step out, and store variables..

edit:
Actually, Ive got a better idea (now that I see what youre sending) really ought to read these things all the way through.. anyway. Itll come soon.
Amended on Sun 29 Jun 2003 10:25 AM by Flannel
USA #18

Sub OnNewHp(strAliasName, strOutput, arrWildCards)
  dim spchange, hpchange, hpsign, spsign
  newhp = world.getvariable ("newhp")
  newsp = world.getvariable ("newsp")
  oldsp = world.getvariable ("oldsp")
  oldhp = world.getvariable ("oldhp")
  totalhp = world.getvariable ("totalhp")
  totalsp = world.getvariable ("totalsp")
  if newhp = oldhp then              \
    setvariable "oldhp", newhp        \
  end if                               \  See
  if newsp = oldsp then                / Below
    setvariable "oldsp", newsp        /
  end if                             /
  hpchange = oldhp - newhp
  spchange = oldsp - newsp
  if hpchange >= "0" then
    hpsign = "+"
  else
    hpsign = "-"
    hpchange = abs(hpchange)
  end if
  if spchange >= "0" then
    spsign = "+"
  else
    spsign = "-"
    spchange = abs(spchange)
  end if
  if spchange + hpchange then 
    World.Send "ps Hp: " & newhp & "(" & totalhp & ") " & hpsign & hpchange & " Sp: "_
 & newsp & "(" & totalsp & ") " & spsign & spchange & ""
  end if
  world.setvariable "oldhp",newhp
  world.setvariable "oldsp",newsp
end sub


edit:
Added the underscore after SP: I THINK thats the VBscript line continuation... Just hate seeing the forum have a horiz. scroll, to fix it, delete the underscore, and the carriage return.
probably want to delete it anyway, since the underscore might not work.
Amended on Sun 29 Jun 2003 11:45 AM by Flannel
Greece #19
if newhp = oldhp then
setvariable "oldhp", newhp
end if

Redundant. If newhp is 10, and oldhp is also 10, then that portion will set oldhp to 10, but it was 10 to begin with.

if newsp = oldsp then
setvariable "oldsp", newsp
end if

Same.

Also, why do the sign thing and not just have it display the native, i.e. "10" for +10 hp and "-10" for -10?
USA #20
Youre right, I didnt think about that first part, just copied it.

Anyway, The plus thing is how they originally had it setup, and it makes sense. (And was trying to keep output the same, which is why I have the empty string at the end of the line)

They have newstat(total)+/-change
Thats waht the double dipping was, one for positive, one for negative (originally had native for -, but that would require more complex code stuff for the send lines. This made it a lot easier.

COULD have done.... "" as sign (when negative) and then used native. That crossed my mind too, but I decided to go with this, since its more symmetric.
Amended on Sun 29 Jun 2003 11:43 AM by Flannel
Canada #21
For comparison's sake, I'll offer you a large chunk of code from one of my own plugins. (The Plugin is unreleased, still needs much work, and I barely script lately).

On my mud, instead of 'spell points' [SP], we have 'concentration points' [CP].

On my mud, healer characters can choose a "heal all" spell which sends a wave of healing to the entire mud. For fun, I decided to script a thank-you informing the healer of how many HP's they healed. I use the "thank" emote which will accept an argument for additional text to add to the emote.

Thanking the healer is actually a bit tricky, because: If I am in combat, the heal the world message comes between two health bars, with the added hit points being in the health bar after the heal all line, but if I am not in combat, a health bar is presented first, and then the heal all line is presented. In order to offer an accurate message to the healer, I track the most recent health bar indicating my current health, plus the previous two health bars. (I can turn autothanks on/off via an alias).

In direct regards to what you are doing, I also have the ability to display the difference between health bars. I call this "Tickinfo". I have an alias to turn "Tickinfo" on/off via an alias, or I can just use the alias "Tick" to present the information just once.

Since the health bar is slighly different while in combat (It has an additional "OPPONENT: Perfect Health" added to it), I can detect whether I am in combat or not. This can be useful, so I track this information as well.

The script includes calls to another plugin of mine, "StatLine", which is used to present information on the status line in MUSHclient. (That one is available at my website).

Some of the triggers have &Prompt; at the beginning of them. This is a special substring meant to capture my prompt, in case it is displayed on the same line as the text I want to trigger on. The actual expression for matching my prompt is declared in an ENTITY value at the beginning of the plugin:

<!DOCTYPE muclient [
	<!ENTITY NoteColour "#FF64B9" >
	<!ENTITY NamePrefix "AOD_MON:" >
	<!ENTITY Prompt "(?:&gt; )*" >
	]>

I find that a very useful means of offering flexability in plugins. Someone with a different prompt only need change that one value, and all the triggers in my plugin should still work.

Finally, there may be subroutines and functions called in this quoted script, which have not been quoted. (Like my "Padleft" function for example).

<!--	===== Monitor Health Status =================================== -->

<triggers>
	<trigger
		enabled="y"
		match="^&Prompt;HP\: \[(.*?)\/(.*?)\]  CONC\: \[(.*?)\/(.*?)\]$"
		name="MONITOR_Health_Status"
		regexp="y"
		script="Get_Health_Status"
		sequence="100"
		>
	</trigger>
	<trigger
		enabled="y"
		match="^&Prompt;HP\: \[(.*?)\/(.*?)\]  CONC\: \[(.*?)\/(.*?)\]  OPPONENT\: (.*?)$"
		name="MONITOR_Health_Status_InCombat"
		regexp="y"
		script="Get_Health_Status"
		sequence="100"
		>
	</trigger>
</triggers>

<aliases>
	<alias
		name="MON_TickInfo"
		script="Toggle_TickInfo"
		match="^TickInfo(?:[ ]+(.*))?$"
		enabled="y"
		regexp="y"
		ignore_case="y"
		>
	</alias>
	<alias
		name="Display_TickInfo"
		script="Display_TickInfo"
		match="^tick$"
		enabled="y"
		regexp="y"
		ignore_case="y"
		>
	</alias>
</aliases>

<script>
<![CDATA[

Dim HPc_Full,  HPc_Current,  HPc_Percent,  CPc_Full,  CPc_Current,  CPc_Percent
Dim HPp_Full,  HPp_Current,  HPp_Percent,  CPp_Full,  CPp_Current,  CPp_Percent
Dim HPp2_Full, HPp2_Current, HPp2_Percent, CPp2_Full, CPp2_Current, CPp2_Percent

Sub InCombat_False (TriggerName, TriggerLine, arrWildcards)
	World.SetVariable "InCombat", vbsFalse
	World.SetVariable "InCombatStatus", "Peace."
	World.CallPlugin "5c582b1da52fd6a9d5d912a8", "AddString", "19_InCombatStatus" & _
		Chr(10) & World.GetVariable("InCombatStatus")
	If ThankHealer Then Send_Thank_Healer
End Sub

Sub InCombat_True (TriggerName, TriggerLine, arrWildcards)
	World.SetVariable "InCombat", vbsTrue
	World.SetVariable "InCombatStatus", "Combat!"
	World.CallPlugin "5c582b1da52fd6a9d5d912a8", "AddString", "19_InCombatStatus" & _
		Chr(10) & World.GetVariable("InCombatStatus")
	If ThankHealer Then Send_Thank_Healer_InCombat
End Sub

Sub Get_Health_Status (TriggerName, TriggerLine, arrWildcards)
	Dim StatusLineText
	HPp2_Current = HPp_Current
	HPp2_Full = HPp_Full
	HPp2_Percent = HPp_Percent
	CPp2_Current = CPp_Current
	CPp2_Full = CPp_Full
	CPp2_Percent = CPp_Percent
	HPp_Current = HPc_Current
	HPp_Full = HPc_Full
	HPp_Percent = HPc_Percent
	CPp_Current = CPc_Current
	CPp_Full = CPc_Full
	CPp_Percent = CPc_Percent
	HPc_Current = CStr(CInt(arrWildcards(1)))
	HPc_Full = CStr(arrWildcards(2))
	HPc_Percent = CStr(Round(((CInt(HPc_Current) / CInt(HPc_Full)) * 100)))
	CPc_Current = CStr(arrWildcards(3))
	CPc_Full = CStr(arrWildcards(4))
	CPc_Percent = CStr(Round(((CInt(CPc_Current) / CInt(CPc_Full)) * 100)))
	If World.GetVariable("TickInfo") Then Display_TickInfo "Get_Health_Status", TriggerLine, arrWildcards
	StatusLineText = "HP: " & HPc_Percent & "%  CP: " & CPc_Percent & "%"
	World.CallPlugin "5c582b1da52fd6a9d5d912a8", "AddString", "12_HealthStatus" & _
		Chr(10) & StatusLineText
	If CStr(arrWildcards(5)) <> Empty Then
		InCombat_True "Get_Health_Status", TriggerLine, arrWildcards
	Else
		InCombat_False "Get_Health_Status", TriggerLine, arrWildcards
	End If
End Sub

Sub Display_TickInfo (AliasName, AliasLine, arrWildcards)
	World.ColourNote NoteColour, "", "HP: " & _
		PadLeft(CStr(CInt(HPc_Current) - CInt(HPp_Current)), Len(HPc_Current) + 1) & _
		PadLeft("CONC: ", Len(HPc_Full) + 10) & _
		PadLeft(CStr(CInt(CPc_Current) - CInt(CPp_Current)), Len(CPc_Current) + 1)
End Sub

Sub TickInfo_On
	World.SetVariable "TickInfo", True
	World.SetVariable "TickInfoStatus", "TickInfo: On"
	World.ColourNote NoteColour, "", World.GetVariable("TickInfoStatus")
End Sub

Sub TickInfo_Off
	World.SetVariable "TickInfo", False
	World.SetVariable "TickInfoStatus", "TickInfo: Off"
	World.ColourNote NoteColour, "", World.GetVariable("TickInfoStatus")
End Sub

Sub Toggle_TickInfo (AliasName, AliasLine, arrWildcards)
	Dim Argument
	Argument = Trim(LCase(arrWildcards(1)))
	If (Argument = "on")  or (Argument = "yes") or (Argument = "true")  Then Argument = "y"
	If (Argument = "off") or (Argument = "no")  or (Argument = "false") Then Argument = "n"
	If Argument = "y" Then
		TickInfo_On
	ElseIf Argument = "n" Then
		TickInfo_Off
	Else
		If World.GetVariable("TickInfo") Then
			TickInfo_Off
		Else
			TickInfo_On
		End If
	End If
End Sub

]]>
</script>

<!--	===== Thank Healer ============================================ -->

<aliases>
	<alias
		name="MON_AutoThank"
		script="Toggle_AutoThank"
		match="^(?:athank|autothank)(?:[ ]+(.*))?$"
		enabled="y"
		regexp="y"
		ignore_case="y"
		>
	</alias>
</aliases>

<triggers>
	<trigger
		enabled="y"
		match="^&Prompt;(\w*) lets (?:his|her) healing powers flow through the world\.$"
		name="MONITOR_Heal_The_World"
		regexp="y"
		script="Set_Healer_To_Thank"
		sequence="100"
		>
	</trigger>
</triggers>

<script>
<![CDATA[

Dim ThankHealer,    ThankHealerName

Sub Set_Healer_OptOut
End Sub

Sub Set_Healer_To_Thank (TriggerName, TriggerLine, arrWildcards)
	ThankHealerName = CStr(arrWildcards(1))
	ThankHealer = vbsTrue
	If CInt(HPp_Percent) = 100 Then ThankHealer = vbsFalse
End Sub

Sub Send_Thank_Healer
	Dim Message
	ThankHealer = vbsFalse
	If World.GetVariable("AutoThank") Then
'		Message = " HP: [" & HPp2_Current & "/" & HPp2_Full & "] - to -> HP: [" & HPp_Current & "/" & HPp_Full & "]"
		Message = " for " & CStr(HPp_Current - HPp2_Current) & " HP's worth of healing"
		World.LogSend "thank " & ThankHealerName & Message
	End If
End Sub

Sub Send_Thank_Healer_InCombat
	Dim Message
	ThankHealer = vbsFalse
	If World.GetVariable("AutoThank") Then
'		Message = " HP: [" & HPp_Current & "/" & HPp_Full & "] - to -> HP: [" & HPc_Current & "/" & HPc_Full & "]"
		Message = " for " & CStr(HPc_Current - HPp_Current) & " HP's worth of healing"
		World.LogSend "thank " & ThankHealerName & Message
	End If
End Sub

Sub AutoThank_On
	World.SetVariable "AutoThank", True
	World.SetVariable "AutoThankStatus", "AutoThank: On"
	World.ColourNote NoteColour, "", World.GetVariable("AutoThankStatus")
End Sub

Sub AutoThank_Off
	World.SetVariable "AutoThank", False
	World.SetVariable "AutoThankStatus", "AutoThank: Off"
	World.ColourNote NoteColour, "", World.GetVariable("AutoThankStatus")
End Sub

Sub Toggle_AutoThank (AliasName, AliasLine, arrWildcards)
	Dim Argument
	Argument = Trim(LCase(arrWildcards(1)))
	If (Argument = "on")  or (Argument = "yes") or (Argument = "true")  Then Argument = "y"
	If (Argument = "off") or (Argument = "no")  or (Argument = "false") Then Argument = "n"
	If Argument = "y" Then
		AutoThank_On
	ElseIf Argument = "n" Then
		AutoThank_Off
	Else
		If World.GetVariable("AutoThank") Then
			AutoThank_Off
		Else
			AutoThank_On
		End If
	End If
End Sub

]]>
</script>

Oh, the empty sub "Set_Healer_OptOut" is just a reminder that I intend to write additional code to restrict thanking certain healers who do not wish to be thanked (they find it too spammy).

Argh, the forum software removed a \ character here and there, particularly in the quoted triggers, escaping square brackets. I have tried to fix them.
Amended on Mon 30 Jun 2003 05:08 PM by Magnum
Australia Forum Administrator #22
Quote:

Argh, the forum software removed a \ character here and there, particularly in the quoted triggers, escaping square brackets. I have tried to fix them.


Magnum, take the plugin (copy it), paste it into a blank MUSHclient notepad window, select "Quote Forum Codes" - that will fix all backslashes and square brackets. Then post it. You should always do that when posting code snippets with backslashes and/or square brackets, AND you are using Forum Codes.
Amended on Mon 30 Jun 2003 09:30 PM by Nick Gammon
USA #23
well, i use '+10' in place of '10' because there are numerous idiots on my mud :)

and your right, it is redundant, ill remove that part.

Thanks for your code Flannel, it works fine.