View unanswered posts | View active topics It is currently Fri Apr 17, 2026 11:54 pm



Reply to topic  [ 50 posts ]  Go to page Previous  1, 2, 3, 4  Next
 Simple read file to an array 
Author Message
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post Re: Simple read file to an array
Parrothead wrote:
Its only a "closed" set if the planet holds more EQ than the universe can buy


No, that isn't the way it works. Why is this even
a debate? You're arguing against something that's
proven. WTF?

Parrothead wrote:
20k secotr 40% PD 4000 EQ buyers ...60,00,000 eq @ 1500 per buyer


Except that isn't the situation, at all. We aren't
talking about a general ptrade across the entire uni,
we're talking about trading a closed set of ports,
ie: an upgraded ports list.

Yes if you want to compare a ptrader that hits every
figged port in the uni to one that only hits good MCICs
that are close, obviously the latter will do better. But
that isn't what's being discussed at all, and trading
a set of upgraded ports will always beat trading the
universe.

Parrothead wrote:
I don't trade that much at a time therefore I have my pick of subsets.


Sigh...

Parrothead wrote:
A simple BFS allows only one subset.


Sigh...

Parrothead wrote:
Given a once a day trading cycle and 100% regen. A bfs will go to the same port everytime.


You're confusing the problem of list selection with route
selection.

_________________
May the unholy fires of corbomite ignite deep within the depths of your soul...

1. TWGS server @ twgs.navhaz.com
2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads
3. Open IRC chat @ irc.freenode.net:6667 #twchan
4. Parrothead wrote: Jesus wouldn't Subspace Crawl.

*** SG memorial donations via paypal to: dpocky68@booinc.com
Image


Sun Nov 28, 2010 10:19 pm
Profile ICQ WWW
Commander
User avatar

Joined: Wed May 03, 2006 2:00 am
Posts: 1722
Location: USA
Unread post Re: Simple read file to an array
Maybe that is what you are talking about Sing but I am not.

Moving a planet thru a closed list of ports/sectors/whatever has only one solution for least gas use.

There is nothing to talk about.........

Why are you banging your head against a wall talking about someone's list That convo was over on page one. This is page three.

_________________
Coconut Telegraph (ICQ)#586137616
Team Speak3@ 220.244.125.70:9987
Founding Member -=[Team Kraaken]=- Winner of Gridwars 2010 - Ka Pla
Image
Jesus wounldn't Subspace Crawl


Sun Nov 28, 2010 10:42 pm
Profile ICQ YIM
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post Re: Simple read file to an array
Parrothead wrote:
Moving a planet thru a closed list of ports/sectors/whatever has only one solution for least gas use.


No, it doesn't. It has one solution for least gas use per
starting point, assuming the list doesn't change. And
that's a good thing. Don't confuse route selection with
list selection.

Parrothead wrote:
Why are you banging your head against a wall talking about someone's list That convo was over on page one. This is page three.


Except you're missing the applications.

The only time filtering for MCIC/distance provides an
advantage is when you're working on small non upgraded
ports. Except in most circumstances, the goal of working
on small non-upgraded ports is to find good ports (unknowns)
to upgrade. So by adding distance+mcic as a filter, you're
reducing that exploration and potentially decreasing future
profits.

Its a small, very limited edge (1 day), with a sharp trade-off.

Granted, a BFS-based ptrader approach may not as unique.
But it's as effective, and in many cases more effective, than
factoring in an cash/turn or ore/turn, which simply ends up
costing more ore (increasing turns spent on ore, decreasing
net profit per turn).

Just because something is more complex doesn't mean it's
better.

_________________
May the unholy fires of corbomite ignite deep within the depths of your soul...

1. TWGS server @ twgs.navhaz.com
2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads
3. Open IRC chat @ irc.freenode.net:6667 #twchan
4. Parrothead wrote: Jesus wouldn't Subspace Crawl.

*** SG memorial donations via paypal to: dpocky68@booinc.com
Image


Sun Nov 28, 2010 11:11 pm
Profile ICQ WWW
Commander
User avatar

Joined: Wed May 03, 2006 2:00 am
Posts: 1722
Location: USA
Unread post Re: Simple read file to an array
Your not looking at the math Sing. Just being contrary for the sake of being contrary is not productive.

Sigh.... is not productive.

I am sure you will need the last word....So please feel free.

_________________
Coconut Telegraph (ICQ)#586137616
Team Speak3@ 220.244.125.70:9987
Founding Member -=[Team Kraaken]=- Winner of Gridwars 2010 - Ka Pla
Image
Jesus wounldn't Subspace Crawl


Mon Nov 29, 2010 11:51 am
Profile ICQ YIM
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post Re: Simple read file to an array
Parrothead wrote:
Your not looking at the math Sing. Just being contrary for the sake of being contrary is not productive.


No, I am. I'm saying your math is incomplete.

Think about it. How can you exceed the maximum
profit for a group of ports? You can't. All you can do
is try to select a different group of ports. That's list
selection, not route selection (whether it happens
while you move or not, its still list selection). When
the list is pre-selected for you, that's no longer an
option.

_________________
May the unholy fires of corbomite ignite deep within the depths of your soul...

1. TWGS server @ twgs.navhaz.com
2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads
3. Open IRC chat @ irc.freenode.net:6667 #twchan
4. Parrothead wrote: Jesus wouldn't Subspace Crawl.

*** SG memorial donations via paypal to: dpocky68@booinc.com
Image


Mon Nov 29, 2010 8:19 pm
Profile ICQ WWW
Ensign

Joined: Sun Mar 06, 2011 12:22 am
Posts: 205
Unread post Re: Simple read file to an array
Hey guys, I have played on and off for at least fifteen years, and it seems like I am finally figuring out some stuff. I am trying to learn scripting, but it is going slowly. A friend taught me some programming back in the days of Quick Basic, but I only programmed bits and pieces here and there. He said that he learned by finding other peoples' programs, taking them apart, and figuring out the components.

I am not having much luck with that and I am not having much success getting public scripts to work.

I was trying to make a p-trade script. I was proud of myself for figuring out how to make TWX Proxy make SWATH open its port search window. I was going through the messages and Singularity, I saw your script, and thought that it was exactly what I needed. I kind of got lost in the argument. Maybe I should look up "Heuristics." :) I took the small part of my script, spliced it in yours, went to work, and like an hour later I had made a hundred and thirty milion credits.

Then my computer completely died and it was difficult to recreate my small part. When I tried to run the script I received the error:

Script compilation error: Unknown command 'READTOARRAY', line 29 (0PTRADE.TS)

Elder Dagger, did you take out the command readToArray? What should I use instead?

I would appreciate any help; I have learned a great deal in these forums!


Sun Mar 06, 2011 1:32 am
Profile
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post Re: Simple read file to an array
What version of TWX are you using? readToArray is supported in 2.04 and above. It might have been supported in 2.03 but I don't remember.

If you are using 2.04 or above, post line 29 of your code.

_________________
               / Promethius / Enigma / Wolfen /

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


Mon Mar 07, 2011 12:34 am
Profile ICQ
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post Re: Simple read file to an array
TWX is complaining about line 29. If "readtoarray" is the first word on line 29, then you are indeed trying to run an older version of TWX, as the readtoarray command was added in v2.04.

Glad to hear you are trying to script, and having some success. Start up a new thread with any specific scripting questions. We're all usually pretty eager to answer questions, and will often provide snippets if you ask nicely.

Regards,
+EP+

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


Tue Mar 08, 2011 1:32 am
Profile WWW
Ensign

Joined: Sun Mar 06, 2011 12:22 am
Posts: 205
Unread post Re: Simple read file to an array
Thanks guys! Yes! I have 2.03. I could not find anything specifying the version number, but the website says that is the final release. Xide did say in 2005 that he was not supporting it anymore. I am glad that it is in good hands. I am downloading 2.04 from NavHaz right now. Hopefully, this will solve all of my woes, in-game and out, ignorance and lack of ability included. Thanks again!


Tue Mar 08, 2011 8:26 pm
Profile
Ensign

Joined: Sun Mar 06, 2011 12:22 am
Posts: 205
Unread post Re: Simple read file to an array
Okay, I upgraded, ran a CIM and fighter search, which took a while, I have a really slow connection, and I have explored (and run RammaR's gridder) on eighty percent of the 20,000 sectors so far. I do not know how my script worked, I needed to modify it, like looking up an Ascii table. Now I get:

Script compilation error: Access violation at address 00000000. Read of address
00000000

I would greatly appreciate any help! :)
Code:
# ---------------------------------------------------------
# Set this to the appropriate filename
setVar $ports_file ports.txt
# ---------------------------------------------------------

# Promptify
send #145
waitFor #145
setVar $currentline CURRENTLINE
stripText $currentline #8
stripText $currentline #145
getWord $currentline $prompt 1
if ($prompt <> "Citadel")
    send "'This script must run from the Citadel!*"
    halt
end
send "qdc"
waitFor "Planet #"
setVar $GetPlanet CURRENTLINE
stripText $GetPlanet 035
getWord $GetPlanet $Planet 2

# Read ports file
setVar $ports_count 0
setArray $ports_list SECTORS
fileExists $exists $ports_file

if ($exists > 0)
    readToArray $ports_file $list
    setVar $i 1
    while ($i <= $list)
        getWord $list[$i] $word 1
        isNumber $num $word
        if ($num > 0)
            if (($word > 10) AND ($word <= SECTORS))
                add $ports_count 1
                setVar $ports_list[$word] TRUE
            end
        end
        add $i 1
    end
end
if ($ports_count < 1)
    send "'No valid ports to visit!*"
end

# Now we have a hash array that specifies whether
# a given sector is or is not a port to hit. Its
# already clean, so we don't have to re-test each
# sector later.

# ---------------------------------------------------------

# Top loop
:top_loop
    killAllTriggers

    # Scan sector
    send "s*  "
    waitFor "<Scan Sector>"
    waitFor "Sector  :"
    getWord CURRENTLINE $this_sector 3
    waitFor "Citadel command (?=help)"

    # Find the next port to hit
    getNearestWarps $stack $this_sector
    setVar $next_port 0
    setVar $i 1
    while ($i <= $stack)
        setVar $this $stack[$i]
        if ($ports_list[$this] = TRUE)
            setVar $next_port $this
            goto :found_next_port
        end
        add $i 1
    end
    if ($next_port = 0)
        send "'Out of ports!*"
    end
    :found_next_port

     # Pwarp there
    killtrigger nofiglock
    killtrigger toolilore
    killtrigger alreadyth
    killtrigger rdy_to_go
    setTextLineTrigger nofiglock :cant_go "You do not have any fighters in"
    setTextLineTrigger toolilore :no_fuel "You do not have enough"
    setTextLineTrigger alreadyth :p_ready "You are already in that sector!"
    setTextLineTrigger rdy_to_go :p_ready "All Systems Ready, shall we engage?"
    send "p" & $next_port "*y"
    pause

    :cant_go
    killtrigger nofiglock
    killtrigger toolilore
    killtrigger alreadyth
    killtrigger rdy_to_go
    echo ANSI_12 & "Sector " & $next_port & " has no fig down!*"
    setVar $ports_list[$next_port] FALSE
    goto :top_loop

    :no_fuel
    killtrigger nofiglock
    killtrigger toolilore
    killtrigger alreadyth
    killtrigger rdy_to_go
    send "'Planet is too low on ore to continue!*"
    halt

    :p_ready
    killtrigger nofiglock
    killtrigger toolilore
    killtrigger alreadyth
    killtrigger rdy_to_go

    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    send "qqpn" $Planet
    waitFor "Fuel Ore"
    setVar $portFuel1 CURRENTLINE
    getWord $portFuel1 $portFuel 3
    waitFor "Organics"
    setVar $portOrganics1 CURRENTLINE
    waitFor "Equipment"
    setVar $portEquipment1 CURRENTLINE
    if ($portFuel = "Selling")
      goto :sellOrganics
    end

    :sellFuel
    getword $portFuel1 $portBuying 4
    getword $portFuel1 $portPercent 5
    stripText $portPercent 037
    subtract $portPercent 50
    if (0 > $portPercent)
      setVar $portPercent 0
    end
    setVar $sellFuel ($portBuying * $portPercent / 100))
    waitFor "We are buying up to"
    send $sellFuel "*"

    :sellOrganics
    getWord $portOrganics1 $portBuying 3
    getword $portOrganics1 $portPercent 4
    stripText $portPercent 037
    subtract $portPercent 50
    if (0 > $portPercent)
      setVar $portPercent 0
    end
    setVar $sellOrganics ($portBuying * ($portPercent / 100))
    waitFor "We are buying up to"
    send $sellOrganics "*"

    :sellEquipment
    getWord $portEquipment1 $portBuying 3
    getword $portEquipment1 $portPercent 4
    stripText $portPercent $portPercent 037
    subtract $portPercent 50
    if (0 > $portPercent)
      setVar $portPercent 0
    end
    setVar $sellEquipment ($portBuying * ($portPercent / 100))
    waitFor "We are buying up to"
    send $sellEquipment "*"   

    waitFor "Command [TL="
    send "l" $Planet "*c"
   
    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    # Clear from the list and hit the next
    setVar $ports_list[$next_port] FALSE
    goto :top_loop

# ---------------------------------------------------------
halt
# ---------------------------------------------------------


How do I attach a file? :)

_________________
Photons away!


Tue Mar 08, 2011 10:48 pm
Profile
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post Re: Simple read file to an array
Ok, script compilation error is usually caused by a
non-standard (non printable) ascii character in the
file. Try copy-pasting into a notepad, then saving
as a .ts file.

If that fails, then do a split debug. That's where you
take half the code, run it, see if the problem persists.
If it does, then you know it's in the first half of the
code, otherwise it's in the latter half. Repeat till you
isolate the problem.

Next, you have...
if (0 > $portPercent)

Port percent is never negative.

And...
stripText $portPercent 037

That doesn't look right...

You don't actually have to do any of that. After
the pwarp, have it scan the sector and cr*q in
a macro burst. That will update the database
with new data...

Ex...
http://www.navhaz.com/files/script.html#VAL_30

Quote:
PORT.FUEL[sector]
Returns the amount of onhand fuel in a port in a specified sector, as stored in the TWX Proxy
Database.


In otherwords, you don't need to parse that
data directly. You can do a port report and let
TWXproxy do the parsing for you.

_________________
May the unholy fires of corbomite ignite deep within the depths of your soul...

1. TWGS server @ twgs.navhaz.com
2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads
3. Open IRC chat @ irc.freenode.net:6667 #twchan
4. Parrothead wrote: Jesus wouldn't Subspace Crawl.

*** SG memorial donations via paypal to: dpocky68@booinc.com
Image


Wed Mar 09, 2011 12:47 am
Profile ICQ WWW
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post Re: Simple read file to an array
You have an unbalanced parenthesis:

about line 139
You have: setVar $sellFuel ($portBuying * $portPercent / 100))
should be: setVar $sellFuel ($portBuying * ($portPercent / 100))

about line 158:

You have: stripText $portPercent $portPercent 037
should be: stripText $portPercent 037
Although I don't know why the line exists or what #037 equates to.

if it is the % sign, the code would be easier to read as: stripText $portPercent "%"

_________________
               / Promethius / Enigma / Wolfen /

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


Wed Mar 09, 2011 1:28 am
Profile ICQ
Ensign

Joined: Sun Mar 06, 2011 12:22 am
Posts: 205
Unread post Awesome! Thanks guys!
Great!

Singularity, the non-standard was the unbalanced parenthesis that Promethius
caught. Had I needed to use the split debug, I would have split your original script from mine. :)

if (0 > $portPercent)

followed

subtract $portPercent 50

I want to sell whatever I have above half.

Regarding the stripText, I was receiving errors and saw that you put the ANSI codes, but neglected to put the "#" before them. Thanks for telling me about that function and for showing the reference--I did not realize that there were reference materials on NavHaz. I went through what there was on TWProxy.com, but that is outdated, so I will take a look at NavHaz, after I simplify my code.

Promethius, thanks for catching the mathematical error. How did I do that?! I changed it to one set of parentheses, since it does not matter if it multiplies or divides first.

Back to the stripText, I had originally just put the number sign, not in quotes, which gave me an error, so I looked how Singularity did it, and messed up that.

"%" is definitely better!

After I made all of those changes my portion was extremely brief, but I was not able to do math directly with game variables. In the end I had:

:sellFuel
setVar $fuel PORT.FUEL[$next_port]
setVar $fuelPercent PORT.PERCENTFUEL[$next_port]
if ($fuelPercent > 50)
subtract $fuelPercent 50
setVar $sellFuel ($fuel * $fuelPercent)
divide $sellFuel 100
else
setVar $sellFuel 0
end
waitFor "We are buying up to"
send $sellFuel "*"

It seems bulky, but it is working, though! Thanks again, guys! :)

_________________
Photons away!


Wed Mar 09, 2011 2:21 pm
Profile
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post Re: Simple read file to an array
The math in that last routine is clear, but you can perform multiple math operations using a single setVar command. The equivalent to that last routine would be:
:sellFuel
if (PORT.PERCENTFUEL[$next_port] > 50)
setVar $sellFuel (((PORT.PERCENTFUEL[$next_port] - 50) * PORT.FUEL[$next_port]) / 100)
else
setVar $sellFuel 0
end
waitFor "We are buying up to "
send $sellFuel "*"

I actually remember writing math routines like yours because those were the examples out at the time, and early TWX versions probably required it. But I also remember learning how to do it with setVar, and it's much easier and cleaner... usually.

Regards,
+EP+

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


Wed Mar 09, 2011 9:11 pm
Profile WWW
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post Re: Simple read file to an array
Yeh, all of the 1.x stuff didn't have decimals. I don't
think we had a setprecision until 2.03, did we? And
it didn't really work well until 2.04?

_________________
May the unholy fires of corbomite ignite deep within the depths of your soul...

1. TWGS server @ twgs.navhaz.com
2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads
3. Open IRC chat @ irc.freenode.net:6667 #twchan
4. Parrothead wrote: Jesus wouldn't Subspace Crawl.

*** SG memorial donations via paypal to: dpocky68@booinc.com
Image


Wed Mar 09, 2011 9:52 pm
Profile ICQ WWW
Display posts from previous:  Sort by  
Reply to topic   [ 50 posts ]  Go to page Previous  1, 2, 3, 4  Next

Who is online

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