View unanswered posts | View active topics It is currently Wed Apr 22, 2026 1:34 am



Reply to topic  [ 8 posts ] 
 tried to mod script challenge script, not pretty, help 
Author Message
Ensign

Joined: Wed Nov 06, 2002 3:00 am
Posts: 270
Unread post tried to mod script challenge script, not pretty, help
I was doing a search to find out what the code was for the quickstat | divider symbol (found it, it's #179) when I came across a script challenge. I was looking for the code so that I could write a script to get quickstat info for other scripts, and here it is, code that is much better and tighter than I could ever write with my paltry coding skills. Wanted to say excellent work from all of you coders in that challenge, you're all great coders.
Anyway, I copied it out and tried it, and it worked great. But then, gears in my amateur brain started turning, and I thought "What if I added a 2nd array, that would hold the types? Then, I could write the type and the number of each or what it is both to the file." So, my noob fingers started fumbling in the code, and I added a few lines I thought would work. Added a line to set my 2nd array, added a line to set an increment variable $i. Added a couple more lines and ran it. I got my array, but it didn't turn out like the array from +EP+ 's final code in the script challenge. So maybe you coders could take a look and tell me where I messed up. This is much more advanced coding than I can do, still not sure I understand a couple of the things that +EP+ 's code does. So I look forward to learning from this critique. The code follows. After that is a copy of the arrays from after I run the script.

EP's Excellent work
Code:
:quickStatSub
setArray $quickStat 0
send "/"
waitOn #179 & "Turns "
while (CURRENTLINE <> "")
     # This line means: Grab the block of text between the first set of dividers
     getText #179 & CURRENTLINE & #179 & #179 $block #179 #179
     # Boolean tests added to initialize CORP and PHOT to zero
     while ($block <> "") and ($quickStat[CORP] <> "INITIALIZE_TO_ZERO") and ($quickStat[PHOT] <> "@Zero")
           setVar $capsBlock $block
           stripText $capsBlock ","
           upperCase $capsBlock
           getWord $capsBlock $stat 1
           getWord $capsBlock $quickStat[$stat] 2
           # This next line finally succeeds on the Ship number/type block
           getWord $capsBlock $quickStat[TYPE] 3
           getText CURRENTLINE & #179 & #179 $block $block & #179 #179
     end
     waitOn ""
end
pause


My Mangling of his beautiful work
Code:
:quickStatSub
setArray $quickStat 0
setArray $quickStatType 0
setVar $i 0
send "/"
waitOn #179 & "Turns "
while (CURRENTLINE <> "")
     # This line means: Grab the block of text between the first set of dividers
     getText #179 & CURRENTLINE & #179 & #179 $block #179 #179
     # Boolean tests added to initialize CORP and PHOT to zero
     while ($block <> "") and ($quickStat[CORP] <> "INITIALIZE_TO_ZERO") and ($quickStat[PHOT] <> "@Zero")
           setVar $capsBlock $block
           stripText $capsBlock ","
           upperCase $capsBlock
           getWord $capsBlock $stat 1
           getWord $capsBlock $quickStat[$stat] 2
           getWord $capsBlock $quickStatType[$i] 1
           add $i 1
           # This next line finally succeeds on the Ship number/type block
           getWord $capsBlock $quickStat[TYPE] 3
           getWord $capsBlock $quickStatType[$i] 3
           add $i1
           getText CURRENTLINE & #179 & #179 $block $block & #179 #179
     end
     waitOn ""
end
pause


Variables
Dynamic array of "$QUICKSTAT" (size 29)
"CORP" = "1"
"PHOT" = "0"
"SECT" = "4717"
"TYPE" = "IMPSTA"
"TURNS" = "0"
"CREDS" = "184462"
"FIGS" = "1469"
"SHLDS" = "1000"
"HLDS" = "150"
"ORE" = "150"
"ORG" = "0"
"EQU" = "0"
"COL" = "0"
"ARMD" = "50"
"LMPT" = "2"
"GTORP" = "2"
"TWARP" = "2"
"CLKS" = "2"
"BEACNS" = "2"
"ATMDT" = "2"
"CRBO" = "0"
"EPRB" = "5"
"MDIS" = "10"
"PSPRB" = "NO"
"PLSCN" = "NO"
"LRS" = "HOLO"
"ALN" = "1234"
"EXP" = "1305"
"SHIP" = "3"
"$QUICKSTATTYPE" = "0"

Dynamic array of "$QUICKSTATTYPE" (size 28)
"0" = "SECT"
"1" = "TURNS"
"2" = "CREDS"
"3" = "FIGS"
"4" = "SHLDS"
"5" = "HLDS"
"6" = "ORE"
"7" = "ORG"
"8" = "EQU"
"9" = "COL"
"10" = "PHOT"
"11" = "ARMD"
"12" = "LMPT"
"13" = "GTORP"
"14" = "TWARP"
"15" = "CLKS"
"16" = "BEACNS"
"17" = "ATMDT"
"18" = "CRBO"
"19" = "EPRB"
"20" = "MDIS"
"21" = "PSPRB"
"22" = "PLSCN"
"23" = "LRS"
"24" = "ALN"
"25" = "EXP"
"26" = "CORP"
"27" = "SHIP"
"$STAT" = "SHIP"

The 2nd set of array variables are from my array.


Wed Aug 19, 2009 3:51 pm
Profile
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post Re: tried to mod script challenge script, not pretty, help
A similar method that can give you what you may be looking for, but not as tight as EP's example.

Code:

:Qstats

  send "/"
  setVar $i 1
  setVar $posCounter 1
  setVar $line ""
  waitOn  " Sect "

  while (currentline <> "")
    setVar $line $line & currentLine
    waitOn ""
  end

  replaceText $line #179 " "
  getword $line $qsType[$i] 1


  while ($qsType[$i] <> 0)
    upperCase $qsType[$i]
    getword $line $qsValue ($posCounter + 1)
    setVar $qsText[$qsType[$i]] $qsValue
    add $posCounter 2
    add $i 1
    getword $line $qsType[$i] $posCounter
  end

# =-=-= Output =-=-=

  setVar $writeIt 1
  while ($writeIt < $i)
    gosub :padr
    write "QStest.txt" "qsType: " & $qsType[$writeIt] & $padr &  "   qsText Val: " &  $qsText[$qsType[$writeIt]]
    add $writeIt 1
  end
  write "QSTest.txt" "Phot val: " & $qsText[PHOT]
  write "QSTest.txt" "Sect val: " & $qsText[SECT]
  halt

# =-=- gosub =-=-=
  # align the column in the output
  :padr
    setVar $padr ""
    getLength $qsType[$writeIt] $len
    while ($len <=  12)
       setVar $padr $padr & " "
       add $len 1
    end
    return

_________________
               / Promethius / Enigma / Wolfen /

"A man who has no skills can be taught, a man who has no honor has nothing."


Wed Aug 19, 2009 11:20 pm
Profile ICQ
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post Re: tried to mod script challenge script, not pretty, help
Hey Steve,
As you can see from the dynamic array that is created, the stat names are not created linearly as each value is parsed from the quickstat lines. You see that the CORP and PHOT array indexes are created first. This is done during the first pass of the code, in the second while loop test, on this line:
while ($block <> "") and ($quickStat[CORP] <> "INITIALIZE_TO_ZERO") and ($quickStat[PHOT] <> "@Zero")

Then, the SECT index is created, since it is actually the first value extracted from the quickstat line by getText here:
getText #179 & CURRENTLINE & #179 & #179 $block #179 #179

And then finally, the TYPE index is created, still in the first pass, by this line:
getWord $capsBlock $quickStat[TYPE] 3

Now, understand that the goal of the script challenge wasn't extensibility. That bit of code trades predictability (and legibility) for adaptability and brevity.

More to the point however, to iterate over the types and echo (or write to a file) their values, do this after my original quickstat routine has run:
Code:
setVar $statNames "SECT TURNS CREDS FIGS SHLDS HLDS ORE ORG EQU COL PHOT ARMD LMPT GTORP TWARP CLKS BEACNS ATMDT CRBO EPRB MDIS PSPRB PLSCN LRS ALN EXP SHIP TYPE"
# Now break those into an array, where $quickStatName[1] = "SECT", and so on, and echo them out
setVar $i 1
while ($i <= 28)
   getWord $statNames $stat $i
   echo "*" $stat " - " $quickStat[$stat]
   add $i 1
end


Regards,
+EP+

_________________
Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.


Wed Aug 19, 2009 11:55 pm
Profile WWW
Ensign

Joined: Wed Nov 06, 2002 3:00 am
Posts: 270
Unread post Re: tried to mod script challenge script, not pretty, help
Pro, thanks for that script example, works very well. I can even tell what you are doing with some of it, I will have to study it some more to figure out a few of the things you did there though :D

+EP+ thanks for the further explanation on your original code and the example code for how to set things up to echo or write the values, I am sure someday I will even figure out everything you are talking about - maybe after I take some programming classes? lol :D

Both of those posts were very informative, thanks for taking the time to give me (and others who read this) some useful instruction on these topics.


Thu Aug 20, 2009 12:15 am
Profile
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post Re: tried to mod script challenge script, not pretty, help
You are welcome and several parts of the script I posted are based on things EP has done and showed a lot of us. One major thing I learned about EP is that if you try something and put thought into it, then he seems to be more than willing to help. The bubble finder I wrote was a script I had banged my head against for a long time, and I found a code snippet EP had written and the light clicked for me.

[Edit] Also you will find that you are always tweaking code. The code I posted in its tightest form (for me anyway) is:

Code:
:Qstats
  send "/"
  setVar $posCounter 1
  setVar $line ""
  waitOn  " Sect "
  while (currentline <> "")
    setVar $line $line & currentLine
    waitOn ""
  end
  replaceText $line #179 " "
  getword $line $qsType 1
  while ($qsType <> 0)
    upperCase $qsType
    getword $line $qsText[$qsType] ($posCounter + 1)
    add $posCounter 2
    getword $line $qsType $posCounter
  end
  return


All data references would have to be to $qsText[XXXX] where XXXX is SECT, TURNS, ORE, or whatever it is that you want from the QS line. A var dump looks like:
Dynamic array of "$QSTEXT" (size 28)
"SECT" = "1641"
"TURNS" = "0"
"CREDS" = "39,701,433"
"FIGS" = "200,000"
"SHLDS" = "16,000"
"HLDS" = "255"
"ORE" = "255"
"ORG" = "0"
"EQU" = "0"
"COL" = "0"
"ARMD" = "0"
"LMPT" = "0"
"GTORP" = "13"
"TWARP" = "2"
"CLKS" = "0"
"BEACNS" = "0"
"ATMDT" = "19"
"CRBO" = "0"
"EPRB" = "0"
"MDIS" = "11"
"PSPRB" = "No"
"PLSCN" = "Yes"
"LRS" = "Holo"
"ALN" = "-479,107"
"EXP" = "32,809"
"CORP" = "3"
"SHIP" = "6"

If you checked your corp number with $qsText[CORP] and was not on a corp, it "should" return 0 even though the array was not created. It worked that way in the previous script because I did not have photons and the script did not crash. This did not answer your original question tho, but it shows yet another way of doing something.

[/Edit]

_________________
               / Promethius / Enigma / Wolfen /

"A man who has no skills can be taught, a man who has no honor has nothing."


Thu Aug 20, 2009 12:30 am
Profile ICQ
Ensign

Joined: Wed Nov 06, 2002 3:00 am
Posts: 270
Unread post Re: tried to mod script challenge script, not pretty, help
Thanks Pro, some nice code there. I noticed a return there in the code in the last post, is that in there so that you can use it as an include and use the gosub command in another script that calls it?

And yes, I noticed what you were saying, you and +EP+ and many other scripters (I wish all the other scripters come to mind, I hate to leave out credit to others who are also helpful, although I am sure it would make my post much larger, there are so many of you that help) seem to be very helpful with noob scripter questions or questions on advanced stuff for scripters who might be running into a bit of a problem somewhere in their script - it's one of the things I enjoy about the forum.

I like the script challenges although they are usually above my level of scripting, what I am able to figure out from the posts are great learning experiences.


Thu Aug 20, 2009 11:40 am
Profile
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post Re: tried to mod script challenge script, not pretty, help
Yes, the return is for a gosub, but not necessarily just for an include. Gosubs are used in standalone (no includes) a lot to eliminate a lot of coding. Typically a quick stat would be an include since once written it usually doesn't require changes. Key word usually because some situations require the same basic code but with additions/changes.

_________________
               / Promethius / Enigma / Wolfen /

"A man who has no skills can be taught, a man who has no honor has nothing."


Thu Aug 20, 2009 1:54 pm
Profile ICQ
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post Re: tried to mod script challenge script, not pretty, help
Promethius wrote:
One major thing I learned about EP is that if you try something and put thought into it, then he seems to be more than willing to help.

Beautiful, I couldn't have said it better myself. And I'm sure this goes for just about every scripter out there, that we don't want to write your scripts for you, but we're more than willing to nudge you in the right direction. Teach a man to fish, and all that.

Thanks for the props,
+EP+

_________________
Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.


Fri Aug 21, 2009 11:36 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

Who is online

Users browsing this forum: No registered users and 27 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by wSTSoftware.