View unanswered posts | View active topics It is currently Thu Jan 01, 2026 4:28 am



Reply to topic  [ 6 posts ] 
 Script Help Please - Bubble Fighter Deployment - TWX Proxy 
Author Message
Staff Sergeant

Joined: Wed Oct 20, 2004 2:00 am
Posts: 18
Location: USA
Unread post Script Help Please - Bubble Fighter Deployment - TWX Proxy
Script newbie here. Need help with a TWX Proxy script I'm developing--hopefully this is the appropriate place to ask.

What I want to do is lay 4 defensive fighters in every sector in a bubble. I have a list of the sectors in a text file called bubble1.txt, listed one per line like this:
1111
2222
3333
4444
5555
...etc...

Here's the script, as I have it so far. The part that sets the array, and advances the variables is cut and pasted from the TWX Proxy help file, the rest is hack and slash by me.

Code:
# load bubble list
goto :start
   :start
    setArray $BubbleList SECTORS
    setVar $i 1
    read bubble1.txt $bubble $i
      :going
      if ($bubble <> EOF)
        killAllTriggers
        setVar $BubbleList[$bubble] 1
        add $i 1
        read bubble1.txt $bubble $i
         send $bubble "*"
               waitFor "] (?=Help)? :"
        setDelayTrigger delay :sendit 1000
              :sendit
        send "f4*cd"
      end
     if ($bubble <> EOF)
       goto :going
      end
echo "ALL DONE DUDES!"


My script keeps sending the strings one after another, without waiting for the trigger, so I always end up in the computer menus. It seems to send in bursts of three or four iterations.

One note: I am using SWATH with the helper OFF to connect to TWX Proxy.

Any help is appreciated!

Thanks!

OVID962


Thu Jul 26, 2012 10:09 am
Profile WWW
Staff Sergeant

Joined: Wed Oct 20, 2004 2:00 am
Posts: 18
Location: USA
Unread post Re: Script Help Please - Bubble Fighter Deployment - TWX Pro
Changing the waitFor to setTextTrigger still has the same problem. I'm obviously doing something wrong.


Fri Jul 27, 2012 1:47 pm
Profile WWW
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post Re: Script Help Please - Bubble Fighter Deployment - TWX Pro
You need a pause after the trigger. There are a lot of other things that I would do different, but it is good to learn.

This might help - check the first post:

viewtopic.php?f=15&t=21677&p=185686&hilit=tutorial#p185686

_________________
               / Promethius / Enigma / Wolfen /

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


Fri Jul 27, 2012 7:45 pm
Profile ICQ
Boo! inc.

Joined: Fri Jan 04, 2002 3:00 am
Posts: 221
Location: Canada
Unread post Re: Script Help Please - Bubble Fighter Deployment - TWX Pro
It has been a long time since I have scripted with twx or played the game for that matter. One thing is right, you did hack it up some :)

I'm going to go through some things for understanding purposes, and then i'll give you suggestions for your code as it is because you can't learn unless you play with what you built. I'll even give a simple example of what i may have done instead and walk you through why i did it. I was hoping some current scripters would chime in here to help you, but since i'm lurking again i'll do what I can.

Firstly, I want to point out a little about how labels and goto works. I noticed that right away you wrote:

goto :start
:start
blah blah

since a script is executed from the top down (some slight exceptions), there is really no need to put goto :start as the first line since :start is right there. the code would run right into your :start label by itself and perform what is in there. labels are a good way to help with looping, or modulate your code. meaning break it up into easier sections. you could use subroutines too like goSub but i won't go into that. that is something for another time. gotos do pretty much the same thing.

then you go down and you create a static array called bubblelist with the preset game setting of SECTORS. meaning if you set your game database to have 5,000 sectors, that is what SECTORS will hold. i'm assuming you built this array to mark if you have completed that sector for future use in your script. That is the only reason I see for keeping that array and setting it to 1 as TRUE.

Then you setup a variable $i as a counter to start at 1. since twx uses 1 as the first line in a file. Good that works. Following with a read command to pull a given line from the file. that works. your reading line #1 so far and stored it into a variable called $bubble.

You setup another label called :going which you are using as a looping point. there are other ways to do this now, but that works just fine. Like I said, i haven't scripted in a long time with twx so I don't even remember what changes they have done to the language. I'm pretty sure they started using WHILE and FOR for loops. but it isn't documented on twxproxy.com website where I think you grabbed references from and hacked code samples.

anyway, lets continue.

you are then checking if $bubble is NOT set to EOF (end of file). <> is NOT equal to. since its a line we want to read, you are killing all triggers and setting the bubblelist array at index $bubble to 1. so say the line was read as 100. you are effectively setting $bubblelist at index 100 to 1. if you did a variable dump you would see a whole lot of variables with $bubblelist and indexes ranging from 1 to SECTORS. $bubblelist[100] equals 1

you increment your $i counter. and then you are reading from the bubbler file right away again at line 2. so effectively you are skipping the first line before you actually do anything and moving onto line two. What I would suggest is reading from the file before you do your check of EOF. but inside our :going label loop. and then remove the second read. that way you start the loop by reading the file. checking if EOF. then you go on to do something... you don't have to increment your counter right away, but you can if you wish like you did.

you send a ENTER key and then wait for the a general prompt from the game with ?=Help. I don't quite understand why you chose to do this. you haven't actually done anything yet. Maybe you were trying to see if you were at a correct prompt. ok, if that is so its admirable. but i'll show you a better way a little later to check your prompt.

You then set your delay trigger called delay firing off to a :send it label lasting 1000 milliseconds. Now with any triggers, you can set them sure, but you have to wait for them in some way or another. that could be using a waitfor right after or using the helper function called PAUSE which was designed for such use. So you would put a pause right after all trigger setting. just one will do. you just want your script to hold up and wait a second until you see something or wait a specified amount of time. you can set triggers all over if you like, but eventually you will have to tell twx to hold up a sec. or it could fire at bad times in the middle of other things you are doing and screw you up.

so like this:

setDelayTrigger delay :sendit 1000
PAUSE

that would wait now until 1000 milliseconds. and then once that is done it will go on to your :sendit label where you have it placing 4 corp fighters in the sector. You then have it checking if the line you read is EOF again. there isn't really any reason to do this again because you did it at the top. but you do have to put a GOTO in there after "end" that last end belongs to your if statement where you were checking if $bubble is NOT equal to EOF. put your GOTO :going right after it. oh i see what you did. you were just checking again incase you still had a line to process, if not then you would send All done dudes. ok that works. but i'll show something i'd do. oh look it is in the reference. ah another time maybe.

Here is an example with some comments to explain why i did what i did:

# Lets check what prompt were are at. If we are at Command prompt, then we can proceed with the script. we set $line to the current line. i then want the first word in that line so that I can see if it is "Command". I could have used CURRENTANSILINE too which would give me ansi codes for helping me check if someone is trying to mess with my script on comms. but i just used the plain text CURRENTLINE

Code:
setVar $line CURRENTLINE
getWord $line $prompt 1
if ($prompt <> "Command")
  GOTO :endScript
end

# set our count to start at line 1 of the file
setVar $count 1
:loop
   READ "bubble.txt" $bubble $count
   IF ($bubble == EOF)
      GOTO :endScript
  END

  # we now probably want to move somewhere, possibly the sector line out of the file.
  # there are a few options.  we could do a goSUB routine.  we could code all in here.
  # lets use goSUB.

  goSUB :MoveMyShip

  # place my fighter.  no check to see if fed :)
  SEND "f4*cd"

  # add counter and then loop again in the file by GOTO :loop
  ADD $count 1
  GOTO :loop


:MoveMyShip
   echo "Moving my ship routine"

  SEND "cm" & $bubble & "*q"
  WaitFor "Command ["

  # now i send RETURN.  which will jump right back to after i sent the goSUB :MoveMyShip
   RETURN

:endScript
    killAllTriggers
    echo "ALL DONE DUDES!"
    HALT




So as you can see the code looks a little different. I tried to piece the script up so I could use calls elsewhere. I didn't use triggers though which you wanted to learn. but i'll try to do an example for you. lets do a silly script that checks players online every 1000 milliseconds. so it just bascially keeps looping around. no need for killAllTriggers here since once it fires its gone. if you had other triggers in there too you would need to kill some.

Code:
:myDelay
  SEND "#"
  setDelayTrigger delay :myDelay 1000
  PAUSE



you could do textlinetriggers like this with killAlltriggers going

Code:
SEND "i"

:reset
killAllTriggers
setTextLineTrigger myTurns :getTurns "Turns to Warp  :"
setTextLineTrigger myName :getMyName "Trader Name    :"
PAUSE

:getTurns
   getWord CURRENTLINE $turns 5
   echo "My turns is " & $turns
   GOTO :reset

:getMyName
   getText CURRENTLINE $name "Trader Name    : " ""
   echo "Hello " & $name &"!*"
   GOTO :reset 



Like i've said at the beginning. its been years since i've coded twx script. so I probably made mistakes. and I did not run any of the examples to ensure they work or not. But maybe it gives you an example to go by or a start anyway. i'm sure some current coders will share too.


Fri Jul 27, 2012 8:31 pm
Profile
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post Re: Script Help Please - Bubble Fighter Deployment - TWX Pro
OVID962 wrote:
What I want to do is lay 4 defensive fighters in every sector in a bubble. I have a list of the sectors in a text file called bubble1.txt, listed one per line like this:
1111
2222
3333
4444
5555
...etc...

Here's the script, as I have it so far. The part that sets the array, and advances the variables is cut and pasted from the TWX Proxy help file, the rest is hack and slash by me.

Code:
# load bubble list
goto :start
   :start
    setArray $BubbleList SECTORS
    setVar $i 1
    read bubble1.txt $bubble $i
      :going
      if ($bubble <> EOF)
        killAllTriggers
        setVar $BubbleList[$bubble] 1
        add $i 1
        read bubble1.txt $bubble $i
         send $bubble "*"
               waitFor "] (?=Help)? :"
        setDelayTrigger delay :sendit 1000
              :sendit
        send "f4*cd"
      end
     if ($bubble <> EOF)
       goto :going
      end
echo "ALL DONE DUDES!"


My script keeps sending the strings one after another, without waiting for the trigger, so I always end up in the computer menus. It seems to send in bursts of three or four iterations.

One note: I am using SWATH with the helper OFF to connect to TWX Proxy.

Any help is appreciated!

Thanks!

OVID962



Look into using readToArray such as:

Code:
# load bubble list
    setVar $i 1
      readToArray bubble1.txt $bubbleList
      while ($i <= $bubbleList)
         if ($bubbleList[$i] > 10) and ($bubbleList[$i] <> STARDOCK)
            send "m " & $bubbleList[$i] & "*  at99* *  f4*cd"
         else
             send "m " & $bubbleList[$i] & "* "
          end
##     add a setTextTrigger followed by pause to pace the script
          add $i 1
      end

echo "ALL DONE DUDES!"


The problem with using this as written will be when $bubbleList[x] is not adjacent to $bubbleList[x+1] and you need to tWarp or get a path to $bubbleList[x+1]. There is also nothing to keep you from running into something nasty because we are not scanning (dScan or holo).

_________________
               / Promethius / Enigma / Wolfen /

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


Sat Jul 28, 2012 7:18 pm
Profile ICQ
Staff Sergeant

Joined: Wed Oct 20, 2004 2:00 am
Posts: 18
Location: USA
Unread post Re: Script Help Please - Bubble Fighter Deployment - TWX Pro
Wow, thanks guys!

I have a lot to digest. I will take a look at this and make changes accordingly. Not putting the PAUSE was definitely a big mistake, and not starting at the 1st line of the bubble1.txt list.

Thanks again!


Sun Jul 29, 2012 11:57 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 58 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.