www.ClassicTW.com
https://mail.black-squirrel.com/

Port upgrader
https://mail.black-squirrel.com/viewtopic.php?f=15&t=31213
Page 1 of 2

Author:  Grey Gamer [ Tue Mar 22, 2011 11:27 am ]
Post subject:  Port upgrader

I made a script to upgrade ports, but it seems to do everything but what I want:

Code:
send "o3"
waitFor "How many units do you want to invest?"
setVar $toUpgrade1 CURRENTLINE
stripText $toUpgrade1 "("
getWord $toUpgrade1 $toUpgrade 9
send $toUpgrade "*"
send "o2"
waitFor "How many units do you want to invest?"
setVar $toUpgrade2 CURRENTLINE
stripText $toUpgrade1 "("
getWord $toUpgrade1 $toUpgrade 9
send $toUpgrade "*"
send "o1"
waitFor "How many units do you want to invest?"
setVar $toUpgrade3 CURRENTLINE
stripText $toUpgrade1 "("
getWord $toUpgrade1 $toUpgrade 9
send $toUpgrade "*"
if ($toUpgrade > 0)
  send "q"
end


It sends "0" or "00" whether or not the port is fully upgraded for that product, and it sends a "q" at the end even when $toUpgrade is zero.

Author:  Vid Kid [ Tue Mar 22, 2011 12:42 pm ]
Post subject:  Re: Port upgrader

Quote:
send "o3"
waitFor "How many units do you want to invest?"
setVar $toUpgrade1 CURRENTLINE
stripText $toUpgrade1 "("
getWord $toUpgrade1 $toUpgrade 9
send $toUpgrade "*"
send "o2"
waitFor "How many units do you want to invest?"
setVar $toUpgrade2 CURRENTLINE
stripText $toUpgrade1 "("
getWord $toUpgrade1 $toUpgrade 9
send $toUpgrade "*"
send "o1"
waitFor "How many units do you want to invest?"
setVar $toUpgrade3 CURRENTLINE
stripText $toUpgrade1 "("
getWord $toUpgrade1 $toUpgrade 9
send $toUpgrade "*"
if ($toUpgrade > 0)
send "q"
end


Here is what I would do .. without testing .. changes made

send "o3"
waitOn "How many units do you want to invest?"
setVar $toUpgrade1 CURRENTLINE
getWord $toUpgrade1 $toUpgrade 9
stripText $toUpgrade "("
send $toUpgrade "**"
send "o2"
waitOn "How many units do you want to invest?"
setVar $toUpgrade2 CURRENTLINE
getWord $toUpgrade2 $toUpgrade 9
stripText $toUpgrade "("
send $toUpgrade "**"
send "o1"
waitOn "How many units do you want to invest?"
setVar $toUpgrade3 CURRENTLINE
getWord $toUpgrade3 $toUpgrade 9
stripText $toUpgrade "("
send $toUpgrade "**"
Send "cr*q"

Hope this helps

Author:  Grey Gamer [ Tue Mar 22, 2011 4:45 pm ]
Post subject:  Re: Port upgrader

So, you changed WaitFor to WaitOn and stripTexted before getWording?

Sadly, it is still not upgrading anything. Thanks, though!

Author:  Promethius [ Tue Mar 22, 2011 4:52 pm ]
Post subject:  Re: Port upgrader

You might think of using arrays. Something like what is below that is not tested, but just to give you a thought on arrays:

Code:
setVar $i 3
While ($i > 0)
  send "o" $i
  waitOn "How many units do you want to invest?"
  getword currentline $toUpGrade 9
  stripText $toUpgrade "("
  send $toUpgrade "*"
  subtract $i 1
end
send "*cr*q"

Author:  T0yman [ Tue Mar 22, 2011 7:46 pm ]
Post subject:  Re: Port upgrader

If you try upping a port that has already been upped this one will try all then then stop. Could add a CN check first and make sure you have minimum $5M credits it you will not have enough cash. I upped 4 ports for a test and it was approx $4.96M each.

Code:
# Port Upgrader

setvar $cat 3
setvar $wait "How many units do you want to invest?"
:top
send "o"
:go
send $cat
waitfor $wait
getWord CURRENTLINE $toUpgrade 9
stripText $toUpgrade "("
if ($toUpgrade > "0")
   send $toUpgrade "*"
   gosub :check
   goto :go
else
   send "0 *"
   gosub :check
   goto :top
end

:check
subtract $cat 1
if ($cat = "0")
   send "q"
   send "cr*q"
   waitfor "Command [TL"
   echo ANSI_15 "**Port Upgraded!!"
   halt
end
return

Author:  Grey Gamer [ Tue Mar 22, 2011 8:47 pm ]
Post subject:  Re: Port upgrader

TOyman, I really appreciate your help, somehow it worked for you, but not for me:

Command [TL=00:00:00]:[8524] (?=Help)? : O
<Construct Starbase>

(Upgrade StarPort)


ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
º Upgrade Starport Production º
ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
º 1 Fuel Ore, costs $250/unit º
º 2 Organics, costs $500/unit º
º 3 Equipment, costs $900/unit º
ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
º Choose 1, 2, 3 or Q to quit º
ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
Choice ? 3

That will cost 900 per unit to upgrade the Equipment
How many units do you want to invest? (0 max, 0 to quit) 0

Command [TL=00:00:00]:[8524] (?=Help)? : O
<Construct Starbase>

(Upgrade StarPort)


ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
º Upgrade Starport Production º
ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
º 1 Fuel Ore, costs $250/unit º
º 2 Organics, costs $500/unit º
º 3 Equipment, costs $900/unit º
ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
º Choose 1, 2, 3 or Q to quit º
ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
Choice ? 2

That will cost 500 per unit to upgrade the Organics
How many units do you want to invest? (5668 max, 0 to quit) 0

Command [TL=00:00:00]:[8524] (?=Help)? : O
<Construct Starbase>

(Upgrade StarPort)


ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
º Upgrade Starport Production º
ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
º 1 Fuel Ore, costs $250/unit º
º 2 Organics, costs $500/unit º
º 3 Equipment, costs $900/unit º
ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
º Choose 1, 2, 3 or Q to quit º
ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
Choice ? 1

That will cost 250 per unit to upgrade the Fuel Ore
How many units do you want to invest? (0 max, 0 to quit)

Port Upgraded!!
Script terminated: scripts\0.ts



Command [TL=00:00:00]:[8524] (?=Help)? : Q
<Quit>
Confirmed? (Y/N)? No

Command [TL=00:00:00]:[8524] (?=Help)? : Q
<Quit>
Confirmed? (Y/N)?

Sect 8524³Turns 59,993³Creds 210,570,067³Figs 100,000³Shlds 13,082³Hlds 255
Ore 150³Org 0³Equ 0³Col 0³Phot 0³Armd 2³Lmpt 90³GTorp 4³TWarp 2³Clks 17
Beacns 600³AtmDt 16³Crbo 0³EPrb 61³MDis 0³PsPrb Yes³PlScn Yes³LRS Holo
Aln 1,710,823³Exp 270,319³Corp 1³Ship 7 TkhOri

Confirmed? (Y/N)?

This is driving me crazy!

Author:  Crosby [ Tue Mar 22, 2011 8:56 pm ]
Post subject:  Re: Port upgrader

well..I can't help but go for the cheap answer:
[botname] maxport f,o,e ... have mom do it!
Even st-109 had a maxport function.

Ok, ok..here's my code snippet.


Code:
# rewrite of Grey's Port Upgrader
setVar $comodity 1
:cycle
  send "o" & $comodity
  waitFor "How many units do you want to invest?"
:howMany
setVar $toUpgrade CURRENTLINE
stripText $toUpgrade "("
getWord $toUpgrade $amount 9
  If $amount = 0
    send "*"
    goto :next
  End

send $amount & "*/*"

:next
waitfor "Command"
If $comodity < 3
  setvar $comodity $comodity + 1
  goto :cycle
End
echo Ansi_15 & "* Finished upgrading. *"
halt


worked for me..but i had a ton of cash. I put in for a maxed category.

Author:  Singularity [ Tue Mar 22, 2011 8:56 pm ]
Post subject:  Re: Port upgrader

Post your current code?

Author:  T0yman [ Tue Mar 22, 2011 9:21 pm ]
Post subject:  Re: Port upgrader

Change the following section, this will add a pause once it stops there, make sure no other scripts are running and run $sv "enter" or if you have scripts running it is $sv cat then we can see what variable it is catching. by your listing above variable cat should = 5668. I am running this on the beta so I am not sure on another version. To stop once you see the variable $z will terminate the script.

Code:
if ($cat = "1")
   echo ANSI_15 $cat
   pause
   send "q"
   send "cr*q"
   waitfor "Command [TL"
   echo ANSI_15 "**Port Upgraded!!"
   halt
end
return

Author:  Vid Kid [ Tue Mar 22, 2011 10:00 pm ]
Post subject:  Re: Port upgrader

ok , I see now one reason you may have problems .. your using a fast computer and a :

WaitOn "How many units do you want to invest? "

needs to be changed to :

WaitOn ", 0 to quit)"

this way the CURRENTLINE will contain the value you seek.

and please use a real name for your file....

not numbers ...

I think all the scripts would work with this fix .. try them and tell us ;)

Author:  Crosby [ Tue Mar 22, 2011 10:24 pm ]
Post subject:  Re: Port upgrader

ahh nice one Vid!

So, to turn this into a teaching thread? Are you saying a fast computer will blaze past that line?
So maybe better to synch up with a 'Waitfor/Waiton' at "per unit to upgrade the" on the line
above it, then another waitfor or trigger?

kicks virtual pebble... Mine worked ok for me :roll:

Author:  ElderProphet [ Tue Mar 22, 2011 11:00 pm ]
Post subject:  Re: Port upgrader

It isn't a question of a fast computer or not. Good scripting technique will avoid problems whether the computer is fast or not. Let me explain the problem Vid is addressing. GG is using the following code:
Code:
send "o3"
waitFor "How many units do you want to invest?"
setVar $toUpgrade1 CURRENTLINE
stripText $toUpgrade1 "("
getWord $toUpgrade1 $toUpgrade 9

And here is the line he's trying to use getWord on:
How many units do you want to invest? (6390 max, 0 to quit)

Now from the code snippet, the waitFor trigger will fire after "invest?", and that is the 8th word in that line. But then he uses getWord to extract word 9. Now many times this will work, but if a packet happens to contain word 8 but not word 9, then a waitFor trigger constructed like this one will fire, but getWord will fail to pull the right data.

Use a setTextLineTrigger when possible, or trigger on unique text that occurs later in the text line than the data you are interested in. Here you can't use setTextLineTrigger because the line he's interested in is waiting on input (and therefore isn't followed by CRLF), so you need to use the 2nd option, and trigger off of something unique and after the desired text, like what Vid mentioned, ", 0 to quit)".

Having said all of that, I've not really studied the code and don't know if this is the real problem or not. But it is a potential problem and will cause problems or bugs that are hard to track down.

+EP+

Author:  Crosby [ Tue Mar 22, 2011 11:32 pm ]
Post subject:  Re: Port upgrader

ok, perhaps that's why my settextlinetrigger wasn't working. I didn't know about this whole CRLF biz. This is only on lines that the game is waiting on input from user?

I thought if you used settextlinetrigger, as I tried, using Gray's text "How many units do you want to invest?" it would grab the whole line. That's why you use a settextlinetrigger instead of a settexttrigger, right?

Anyway, apart from that, good scripting technique has us using the text past our target word for our trigger, ok?

ps Mine still worked. ( oh and note my use of 'ok' at the fore and aft of the verbal upchuck? wasted brilliance... )

Author:  Vid Kid [ Wed Mar 23, 2011 4:13 am ]
Post subject:  Re: Port upgrader

Thank you EP .. the SetTextLineTrigger or SetTextTrigger is better in most scripts.

I personally like to use text after my target , but I wanted to leave GG's script as close to his work
as possible .. otherwise I'de have just pasted my port upgrader.

I think its better to write your own , its a good learning experience.

I also find it nice to use a snippet test.ts to test parts of a script .. like a settextlinetrigger


Code:

:top
SetTextLineTrigger  have :have  ", 0 to quit)"
SetTextTrigger  havenot :havenot  ", 0 to quit)"
Pause

:have
Echo "**" ANSI_11 "LINE  worked*"
Halt

:havenot
Echo "**" ANSI_11 "NO LINE  worked*"
Halt




then type by hand to see which one works then fix up your script.
as things go on .. edit the text at the end of the SetText triggers.

hope this helps

Author:  T0yman [ Wed Mar 23, 2011 6:36 am ]
Post subject:  Re: Port upgrader

I tested mine from work instead of a localhost connection and I found it was running to fast and not clearing as it should have on the $cat variable. I added a delay to slow it down 250ms seemed good but I bumped it a little since I was getting mixed results.
Could probably replace the gosub :delay to waitfor "Choice ?" and get same result.

Code:
# Port Upgrader

setvar $cat 3
setvar $wait "How many units do you want to invest?"
:top
send "o"
:go
gosub :delay
send $cat
waitfor $wait
getWord CURRENTLINE $toUpgrade 9
stripText $toUpgrade "("
if ($toUpgrade > "0")
   send $toUpgrade "*"
   gosub :check
   goto :go
else
   send "0 *"
   gosub :check
   goto :top
end

:check
subtract $cat 1
if ($cat = "0")
   send "q"
   waitfor "Command [TL"
   send "cr*q"
   waitfor "Command [TL"
   echo ANSI_15 "**Port Upgraded!!"
   halt
end
return

:delay
setdelaytrigger one :one 350
pause

:one
return

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