www.ClassicTW.com
http://classictw.com/

Improved Quick Stats Subroutine
http://classictw.com/viewtopic.php?f=15&t=34851
Page 1 of 1

Author:  Adept [ Mon May 02, 2016 11:11 pm ]
Post subject:  Improved Quick Stats Subroutine

I have tested this a bit now and it seems to be working as intended, may still need a bit of tweaking concerning what prompt it activates on, though in most instances that would be the main prompt anyway. Consuming less than 35-lines, awesome!

Notes: Yes and No are converted to Boolean values and 'ITEM' simply refers to a capitalized value of the items within the quick-stats, if not found, TWX defaults the value to 0.


* See revision 2.02 below.


Code:
goSub :UPDATE_QSTATS

...

:UPDATE_QSTATS
#  Improved Quick Stats Subroutine  v1.00.  Update quick stat data as a dynamic array.  Use placeholder:  $_QSTATS[ITEM]
setVar $break 0
setVar $stat_line ""
send "/"
waitFor "Sect"
while ($break = 0)
  setVar $line CURRENTLINE
  getWord $line $ck_line 1
  if ($ck_line = "Command") OR ($ck_line = "Computer") OR ($ck_line = "<StarDock>")
   setVar $break 1
  else
   mergeText $stat_line $line $stat_line
   waitFor " "
  end
end

#  Parse and format data, e.g., data to Boolean, cleanup spaces, etc.
trim $stat_line
replaceText $stat_line #179 " "
stripText $stat_line ","
upperCase $stat_line
replaceText $stat_line "YES" 1
replaceText $stat_line "NO" 0

setVar $a 1
setVar $item ""
while ($item <> "SHIP")
getWord $stat_line $item $a
getWord $stat_line $data ($a + 1)
setVar $_QSTATS[$item] $data
add $a 2
end

return

#  END UPDATE_QSTATS

Author:  Adept [ Tue Jun 14, 2016 1:13 am ]
Post subject:  Re: Improved Quick Stats Subroutine

This compacted revision is more functional, removing the restrictions of the earlier version (tested now in several scripts and thus far has always returned the needed data):

Code:
:QSTATS
#  Improved Quick Stats Subroutine  v2.01.  Update quick stat data as a dynamic array.  Use placeholder:  $_QSS[ITEM]
setVar $break 0
setVar $qss_line ""
send "/"
waitFor "Sect"
while ($break = 0)
setVar $line CURRENTLINE
getWordPos $line $break "Ship"
setVar $qss_line $qss_line & $line
waitFor " "
end
replaceText $qss_line #179 " "
stripText $qss_line ","
upperCase $qss_line
replaceText $qss_line "YES" 1
replaceText $qss_line "NO" 0
setVar $iqss 1
setVar $item ""
while ($item <> "SHIP")
getWord $qss_line $item $iqss
getWord $qss_line $data ($iqss + 1)
setVar $_QSS[$item] $data
add $iqss 2
end
return
#  END QSTATS

Author:  Kaus [ Fri Jun 17, 2016 10:38 am ]
Post subject:  Re: Improved Quick Stats Subroutine

Elegant approach, thanks for sharing.

*thumbs up*

Author:  Adept [ Sat Jun 18, 2016 4:19 am ]
Post subject:  Re: Improved Quick Stats Subroutine

Mucho gracias.

* I made just one small change to make the counter more unique to prevent any conflicts when used in a loop.

Author:  ElderProphet [ Fri Jul 01, 2016 9:49 pm ]
Post subject:  Re: Improved Quick Stats Subroutine

Nice. We had a competition once upon a time to see who could write the shortest quickstats routine. Was a blast, and the smallest was insane, like 15 lines.

Author:  Adept [ Thu Sep 22, 2016 5:12 am ]
Post subject:  Re: Improved Quick Stats Subroutine

Just a small revision to prevent endless looping when subroutine is called while other text is in motion:

Code:
:QSTATS
#  Improved Quick Stats Subroutine  v2.02.  Update quick stat data as a dynamic array.  Use placeholder:  $_QSS[ITEM]
setVar $break 0
setVar $qss_line ""
send "/"
waitFor #179 & "Creds"
while ($break = 0)
setVar $line CURRENTLINE
getWordPos $line $break "Ship"
setVar $qss_line $qss_line & $line
waitFor " "
end
replaceText $qss_line #179 " "
stripText $qss_line ","
upperCase $qss_line
replaceText $qss_line "YES" 1
replaceText $qss_line "NO" 0
setVar $iqss 1
setVar $item ""
while ($item <> "SHIP")
getWord $qss_line $item $iqss
getWord $qss_line $data ($iqss + 1)
setVar $_QSS[$item] $data
add $iqss 2
end
return
#  END QSTATS

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/