if * then * trigger help

Posted by Karl_Newbie on Tue 24 Aug 2004 10:50 PM — 6 posts, 22,306 views.

USA #0
I know how to do simple 'if then' statements for triggers
-----------------
if world.GetVariable("pa") = "0" then
send "command1"
else
end if
--------------

(I have another trigger which changes that variable to 1 at times)

But how can I take it up a notch to include more cause variables with possible alternative conclusions. Ideally it would be sort of like this.

if world.GetVariable("A") = "0" & world.Getvariable ("B") = "0" & world.Getvariable ("C") = "0" then
send "command1"
else
if world.GetVariable("A") = "1" & world.Getvariable ("B") = "0" & world.Getvariable ("C") = "0" then
send "command2"
else
if world.GetVariable("A") = "0" & world.Getvariable ("B") = "0" & world.Getvariable ("C") = "1" then
send "command3"
end if

Is something like that possible?

Basically I have triggers for hunger/thirst/spells status which switch their respective variable to 1 or 0. I want MC to evaluate those variables and send the appropriate command upon matching a generic balance regained trigger and or timer. IE "eat from bowl" if the "I'm hungry" status variable is 1, "drink sip from glass" if the thirsty variable is 1, or go ahead with a "perform action" if all the previous variables are 0.


Amended on Tue 24 Aug 2004 10:53 PM by Karl_Newbie
USA #1
Yes, that is possible.

Except you'd use ElseIf.

And you can also break it down and nest them, such as...


if world.GetVariable("A") = "0" Then
  if world.Getvariable ("B") = "0" then
    if World.getvariable("C") = "0" Then
      send "command1"
    Elseif World.getvariable("C") = "1"
      send "command3"
    end if
  end if
elseif world.GetVariable("A") = "1" & world.Getvariable ("B") = "0" & world.Getvariable ("C") = "0" then 
  send "command2"
end if


Or if you just used 0 and 1, then you could disreguard that elseif (for checking c, since if C isnt 0, its 1)
like this:

if world.GetVariable("A") = "0" Then
  if world.Getvariable ("B") = "0" then
    if World.getvariable("C") = "0" Then
      send "command1"
    Else
      send "command3"
    end if
  end if
Amended on Tue 24 Aug 2004 11:07 PM by Flannel
USA #2
that is one way, but here is yet another way

dim var1, var2, var3

var1 = world.getvariable("A")
var2 = world.getvariable("B")
var3 = world.getvariable("C")

if var1 = 0 And var2 = 0 And var3 = 0 Then
send "command1"
Elseif var3 = 1
send "command3"
end if
if var1 = 1 And var2 = 0 And var3 = 0 then
send "command2"
end if
Amended on Thu 26 Aug 2004 01:43 AM by Jlzink
USA #3
Thanks Flannel and Jlzink. I was getting an error with yours, Flannel. But Jlzink's worked great. Lots of new ideas on how to use this now, thanks.

If anyone reads this, I'm trying to save from opening a new thread, how do I expand a variable inside a timer?

"Drink sip from @activecontainer" for example?
There is no expand variable option listed under timers.

It is sort of like this
----
send "drink sip from (getvariable("activecontainer"))"

----
heh?
I'll get it someday.
Amended on Thu 26 Aug 2004 05:31 PM by Karl_Newbie
USA #4
send "get sip from " & getvariable("activecontainer")
and send to: script.
Or, you can have an alias (which will expand variables), and then the timer sends the alias text (with send to execute).


My earlier errors were probably with the "&" they should be "AND", I was crossing my languages.

You can also use Select Case (for multiple if thens) if you have a long list of possible outcomes. (look in the VBScript Docs)
USA #5
"My earlier errors were probably with the "&" they should be "AND", I was crossing my languages."

Correct :)
Yah, Learning some VBscript might help me, but you good people make it too easy to avoid those docs.