| www.ClassicTW.com https://mail.black-squirrel.com/ |
|
| Loading a saved variation into an include https://mail.black-squirrel.com/viewtopic.php?f=15&t=22443 |
Page 1 of 1 |
| Author: | motrax [ Thu Jul 02, 2009 2:36 am ] |
| Post subject: | 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" |
|
| Author: | Singularity [ Thu Jul 02, 2009 5:20 am ] |
| Post subject: | 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. |
|
| Author: | motrax [ Thu Jul 02, 2009 2:19 pm ] |
| Post subject: | Re: Loading a saved variation into an include |
Thanks for that....cheers |
|
| Author: | motrax [ Thu Jul 02, 2009 4:35 pm ] |
| Post subject: | 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 |
|
| Author: | Singularity [ Thu Jul 02, 2009 5:07 pm ] |
| Post subject: | 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 |
|
| Author: | motrax [ Thu Jul 02, 2009 5:29 pm ] |
| Post subject: | Re: Loading a saved variation into an include |
Thanks. I got it to work.....thanks for your patience and clear explanation.... |
|
| Author: | ElderProphet [ Thu Jul 02, 2009 5:33 pm ] |
| Post subject: | 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 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+ |
|
| Author: | motrax [ Thu Jul 02, 2009 7:02 pm ] |
| Post subject: | 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 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 |
|
| Author: | Singularity [ Fri Jul 03, 2009 6:17 am ] |
| Post subject: | 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. |
|
| Author: | motrax [ Fri Jul 03, 2009 3:03 pm ] |
| Post subject: | 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 |
|
| Author: | LoneStar [ Fri Jul 03, 2009 4:56 pm ] |
| Post subject: | 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. |
|
| Page 1 of 1 | All times are UTC - 5 hours |
| Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |
|