View unanswered posts | View active topics It is currently Thu Apr 23, 2026 6:36 am



Reply to topic  [ 11 posts ] 
 Loading a saved variation into an include 
Author Message
1st Sergeant
User avatar

Joined: Fri Sep 13, 2002 2:00 am
Posts: 38
Location: New Zealand
Unread post Loading a saved variation into an include
How is it possible to load a saved variation into an include when the included file is used??
Is it possible to do this?
I have tried the normal line "loadVar $i"

_________________
"Let slip the carrion dogs of war"


Thu Jul 02, 2009 2:36 am
Profile ICQ YIM WWW
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post Re: Loading a saved variation into an include
You can either pass the variable using:

Code:
setVar $include_filename~variable "blah"
gosub :include_filename~routine
echo $include_filename~return_variable


Or you can use

Code:
saveVar $variable
gosub :include_filename~routine
loadVar $new_variable


The latter will be slower tho, as savevar is passed thru a file.

_________________
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


Thu Jul 02, 2009 5:20 am
Profile ICQ WWW
1st Sergeant
User avatar

Joined: Fri Sep 13, 2002 2:00 am
Posts: 38
Location: New Zealand
Unread post Re: Loading a saved variation into an include
Thanks for that....cheers

_________________
"Let slip the carrion dogs of war"


Thu Jul 02, 2009 2:19 pm
Profile ICQ YIM WWW
1st Sergeant
User avatar

Joined: Fri Sep 13, 2002 2:00 am
Posts: 38
Location: New Zealand
Unread post Re: Loading a saved variation into an include
Can't get it to work
Test Script:
# Test
#setVar $include_filename~variable "blah"
#gosub :include_filename~routine
#echo $include_filename~return_variable

:var
setVar $var 100
saveVar $var

setVar $include_Test~$vari $var
gosub :Test~routine
echo $include_Test~return_$vari
:back
echo "**" & " Back at Test " & $var "**"
halt

include "include\Test"

Include
#Test Include
:routine
echo $include_Test~return_$vari
#trying the saved one as well
echo $include_Test~return_$var
:back
Echo "**" & " Loaded Variation vari " & $vari & " " & $var & "**"
return

_________________
"Let slip the carrion dogs of war"


Thu Jul 02, 2009 4:35 pm
Profile ICQ YIM WWW
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post Re: Loading a saved variation into an include
If you're including "Test" then it's not going not be $include_Test~vari but rather $test~vari

Notice that there's no $ after the ~, and how the name of the first part, before the ~, is the name of the include file. Also you need to include "include\test.ts" ie: have .ts after the name, too.

When referencing it from within the include, it'll be treated as the normally referenced variable, $vari. You won't have a return_var unless you set one.

So in the include called test.ts all you need to do is echo $vari

_________________
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


Thu Jul 02, 2009 5:07 pm
Profile ICQ WWW
1st Sergeant
User avatar

Joined: Fri Sep 13, 2002 2:00 am
Posts: 38
Location: New Zealand
Unread post Re: Loading a saved variation into an include
Thanks. I got it to work.....thanks for your patience and clear explanation....

_________________
"Let slip the carrion dogs of war"


Thu Jul 02, 2009 5:29 pm
Profile ICQ YIM WWW
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post Re: Loading a saved variation into an include
Glad you got it working... here is another small example.

Say you have an include file called myincludes.ts, and in this include you have a routine called :double that takes an input $input, doubles it, and returns it as $output... then it would look something like this:
Code:
{main.ts}
include myincludes.ts
setVar $someNumber 700
echo "*My number was " $someNumber
# Now lets double it by sending it to our include and calling the routine
setVar $myincludes~input $someNumber
gosub :myincludes~double
setVar $someNumber $myincludes~output
echo "*And now it is doubled: " $someNumber
halt
And now the include routine would look like this:
Code:
{myincludes.ts}
:double
setVar $output ($input * 2)
return


Does that make it clearer how to pass the variable to the include and run the routine in the include?

+EP+

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


Thu Jul 02, 2009 5:33 pm
Profile WWW
1st Sergeant
User avatar

Joined: Fri Sep 13, 2002 2:00 am
Posts: 38
Location: New Zealand
Unread post Re: Loading a saved variation into an include
Thanks for the examples EP and Singularity. It is clearer now. Just takes a bit to get my head around some of this programming but I do enjoy playing around with scripts and them having the joy of getting them to work.....sometimes :D BTW. I am playing around with an old Shipcap script of mine. Worked fine to a point. I am working on getting a second wave of figs if the first was unsucessfull.
I get an EOF when it reads the ship files for the second time so I am playing around with an include to divorce the second reading from the first........makes cense to me lol

_________________
"Let slip the carrion dogs of war"


Thu Jul 02, 2009 7:02 pm
Profile ICQ YIM WWW
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post Re: Loading a saved variation into an include
Ah yes.

I pre-cache all of that into an array during load, personally.

For wave count, I assume 0 shields (correcting it if the combat scanner says otherwise) and just attack based on the odds and figcount off a sector scan. After the first wave, I rescan the sector, recalculate and attack again based on the new numbers.

It's a little slower that way (no way to fix that w/o a combat scanner tho), but it will keep firing waves until the ship is captured or I'm out of figs. Add in a way to not attack certain shiptypes (like gbonus stuff) and it works pretty well. Basically it's just a loop.

_________________
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


Fri Jul 03, 2009 6:17 am
Profile ICQ WWW
1st Sergeant
User avatar

Joined: Fri Sep 13, 2002 2:00 am
Posts: 38
Location: New Zealand
Unread post Re: Loading a saved variation into an include
When I do the second scan it reads the ship file and comes up with "EOF Ship type not found" (I echo that message) even if the ship type var has been zeroed.. I was going to use an include to do a re-cap routine. I will have a look at an array.....don't understand them but I will study them and give it a go :D

_________________
"Let slip the carrion dogs of war"


Fri Jul 03, 2009 3:03 pm
Profile ICQ YIM WWW
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post Re: Loading a saved variation into an include
You should consider using the ReadToarray command. If the name of your Ship-file is: ships.txt. let's pretend it has 3 Lines of text in it: Enterra; Ascian Boat; Red Rum.

Code:
setVar $FILE "C:\ships.txt"

FileExists $tst $FILE
if ($tst = 0)
Echo "**Cannot Find File: " & $FILE & "**"
Halt
end

ReadToArray  $FILE $LIST

Echo "*Number Of Lines In File: " & $LIST

SetVar $IDX 1

while ($IDX <= $LIST)
   Echo "*" & $LIST[$IDX]
   Add $IDX 1
end

$LIST is an array of ROWS (one Row for each Line of Text in the Soruce File), each continaing one line form the Text File: Ships.txt.
Code:
$LIST[1] = "Enterra"
$LIST[2] = "Ascian Boat"
$LIST[3] = "Red Rum"


You should test for the file's existence before using ReadToArray, attempting to load a non-existent file will break your Script.

_________________
----------------------------
-= QUANTUM Computing 101: 15 = 3 x 5 ... 48% of the time.


Fri Jul 03, 2009 4:56 pm
Profile ICQ YIM
Display posts from previous:  Sort by  
Reply to topic   [ 11 posts ] 

Who is online

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