| Author |
Message |
|
motrax
1st Sergeant
Joined: Fri Sep 13, 2002 2:00 am Posts: 38 Location: New Zealand
|
 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 |
|
 |
|
Singularity
Veteran Op
Joined: Thu Jun 02, 2005 2:00 am Posts: 5558 Location: USA
|
 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
|
| Thu Jul 02, 2009 5:20 am |
|
 |
|
motrax
1st Sergeant
Joined: Fri Sep 13, 2002 2:00 am Posts: 38 Location: New Zealand
|
 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 |
|
 |
|
motrax
1st Sergeant
Joined: Fri Sep 13, 2002 2:00 am Posts: 38 Location: New Zealand
|
 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 |
|
 |
|
Singularity
Veteran Op
Joined: Thu Jun 02, 2005 2:00 am Posts: 5558 Location: USA
|
 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
|
| Thu Jul 02, 2009 5:07 pm |
|
 |
|
motrax
1st Sergeant
Joined: Fri Sep 13, 2002 2:00 am Posts: 38 Location: New Zealand
|
 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 |
|
 |
|
ElderProphet
Commander
Joined: Tue Oct 07, 2003 2:00 am Posts: 1134 Location: Augusta, GA
|
 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 |
|
 |
|
motrax
1st Sergeant
Joined: Fri Sep 13, 2002 2:00 am Posts: 38 Location: New Zealand
|
 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  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 |
|
 |
|
Singularity
Veteran Op
Joined: Thu Jun 02, 2005 2:00 am Posts: 5558 Location: USA
|
 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
|
| Fri Jul 03, 2009 6:17 am |
|
 |
|
motrax
1st Sergeant
Joined: Fri Sep 13, 2002 2:00 am Posts: 38 Location: New Zealand
|
 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 
_________________ "Let slip the carrion dogs of war"
|
| Fri Jul 03, 2009 3:03 pm |
|
 |
|
LoneStar
Commander
Joined: Fri Jun 09, 2006 2:00 am Posts: 1401 Location: Canada
|
 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 |
|
 |
|