Help! I cannot "return" output window text

Posted by Tamalak on Sun 22 Apr 2001 04:36 PM — 2 posts, 13,200 views.

#0
I cannot for the life of me figure this out. This is what I'm trying to do. At a certain point the game sends me a list of eleven words in a line, like this:

Good Fair Good Good Poor Average Poor Fair Good Good Poor

I am trying to get a script to detect each of these words, convert them into numbers (Good = 5, Average = 3, etc.) and total the numbers (5 + 4 + 5 + 5 + 1 + 3 + 1 + 4 + 5 + 5 + 1 = 39) into a variable. But I cannot get a trigger to fire multiple times without losing the variable in which the total is stored! And I do not see a command for scripts that return strings taken from the output window, so how can I write a script that detects what the words are?? How do I do this? Thanks!
Australia Forum Administrator #1
To do this you need a trigger and have that trigger call a script.

Go into the World Configuration -> Appearance -> Triggers and click on "Add" to create a new trigger.

Fill in the following fields and leave the rest unchanged:


Trigger: ^((Excellent|Good|Fair|Poor|Average) ?)+$
Regular Expression: checked
Label: Assessment
Script: OnAssessment


What this will do is match on any combination of the words Excellent, Good, Fair, Poor, Average (followed by zero or one spaces).

If it gets such a match it then calls the script OnAssessment, which you need to add to the script file (ie. at the end). This example is in VBscript:



sub OnAssessment (strTriggerName, strTriggerLine, arrWildCards)
dim MyArray, i, total
  total = 0
  MyArray = split (strTriggerLine)
  for i = lbound (MyArray) to ubound (MyArray) 
    Select Case MyArray (i) 
      case "Excellent" total = total + 5
      case "Good" total = total + 4
      case "Average" total = total + 3
      case "Fair" total = total + 2
      case "Poor" total = total + 1
    End Select          
  next 
  world.Note "Total is " + cstr (total)
  world.SetVariable "Total", total
End Sub



What this script does is split the trigger line into individual words (with "split"), and then loop through each one adding in the appropriate amount to the total.

The total is then displayed in the output window, and used to set a variable "Total" which you can then use elsewhere.