| www.ClassicTW.com https://mail.black-squirrel.com/ |
|
| Includes https://mail.black-squirrel.com/viewtopic.php?f=15&t=32538 |
Page 1 of 1 |
| Author: | Promethius [ Sun Nov 20, 2011 2:11 am ] |
| Post subject: | Includes |
The information in the help file for using includes in TWX is fairly limited so I put the following together. I am hoping EP will verify it because even though includes can save a lot of time (and errors), I have just started using them in my rewrite project. I used to just copy and paste code snippets, but that has the disadvange of not being easily updated when you figure out a better way to do something. Anyone that has input on this is welcome to add/change and show different ways in this thread. In the main script, add a line to include your file. If it is in a sub directory then you need the path. include "proInc\incProQStats" To make a gosub to the included qStats label gosub :incProQstats~qStats To reference the array $stats[CREDS] remove the $ in front of "stats" and add the include file name as in $incProQstats~ to the array. setVar $cashOnHand $incProQstats~stats[CREDS] To reference the variable $ship1 in the include: setVar $shipSect $incProQstats~ship1 To reference the array $pnum[$i], remove the $ in front of "pnum" and the "i" and add the include $+filename+tilde for both. setVar $planetSect $incProQstats~pnum[$incProQstats~i] You can also use the information in the include direct as you would a normal non-included variable as long as you preface it with the $+filename~ if ($incProQstats~stats[ALN] > 999) if ($incProQstats~ship1 > 10) |
|
| Author: | Grey Gamer [ Wed Nov 23, 2011 3:55 am ] |
| Post subject: | Re: Includes |
Promethius, that is way above my skill level, but I appreciate you sharing that with us! |
|
| Author: | Promethius [ Thu Nov 24, 2011 10:27 am ] |
| Post subject: | Re: Includes |
Grey Gamer wrote: Promethius, that is way above my skill level, but I appreciate you sharing that with us! It looks worse than it is. (Not much of a post for number 3,000) |
|
| Author: | Kaus [ Fri Nov 25, 2011 2:41 pm ] |
| Post subject: | Re: Includes |
Hi Prom Any chance you would want to include/point to a .ts of an actual working example? The tilde plays what significance in the statement? I assume you have to declare the include prior to calling it? I.e. you can't just write a statement in use the tilde to denote the include? Ever finish the multi-ship colonizer w/red option from back in the day? Thanks |
|
| Author: | Promethius [ Fri Nov 25, 2011 5:10 pm ] |
| Post subject: | Re: Includes |
Kaus wrote: Hi Prom Any chance you would want to include/point to a .ts of an actual working example? The tilde plays what significance in the statement? I assume you have to declare the include prior to calling it? I.e. you can't just write a statement in use the tilde to denote the include? Ever finish the multi-ship colonizer w/red option from back in the day? Thanks Kaus - long time, good to see you posting. Yeah, I finished the red colonizer and the public one is out as proEcolonizer 5 or something like that. I am rewriting all of my main scripts, and it is taking a long time. I am not sure exactly what the tilde's purpose is, but it has to be there to connect the include file name to the variable in it. I am guessing it is more to create specific variables to the include so you don't have a $ship variable that clashes with the include's $ship var. I will see what I can come up with that I can post that would be a good example of using the includes. The include can be at the bottom of your script since is appends the include at compile time. |
|
| Author: | Promethius [ Fri Nov 25, 2011 7:01 pm ] |
| Post subject: | Re: Includes |
Hopefully this will give a little more information. This is just a very basic blue colonizing script for fuel cols only. I have my qStats include file at the bottom, but it is a seperate file and not contained in the main script. The incProPlanetInfo file is not attached, but should be descriptive enough on the variable names to understand what I am doing. A partial variable dump looks like the following: Dynamic array of "$INCPROQSTATS~STATS" (size 28) "SECT" = "3667" "TURNS" = "0" "CREDS" = "354104876" "FIGS" = "0" "SHLDS" = "16000" "HLDS" = "230" "ORE" = "0" and "$INCPROPLANETINFO~EQUAMT" = "0" "$INCPROPLANETINFO~EQUCOL" = "0" "$INCPROPLANETINFO~EQUMAX" = "2000000" "$INCPROPLANETINFO~FIGAMT" = "255206" "$INCPROPLANETINFO~FIGMAX" = "7500000" "$INCPROPLANETINFO~FUELAMT" = "5411" "$INCPROPLANETINFO~FUELCOL" = "15700" "$INCPROPLANETINFO~FUELMAX" = "7500000" "$INCPROPLANETINFO~ORGAMT" = "0" "$INCPROPLANETINFO~ORGCOL" = "0" "$INCPROPLANETINFO~ORGMAX" = "2000000" Code: // main file getWord currentLine $prompt 1 if ($prompt = "Planet") send "*tnl1*" // get planet information from the incProPlanetInfo include file goSub :incProPlanetInfo~getPlanetInfo send "q" else // it is a simple script echo ansi_12 "**You must be on the planet's surface to run this!*" halt end // get ship stats from the incProQstats include file goSub :incProQstats~qStats waitFor "Command [TL" echo ANSI_13 "**Enter the max cols to have producing ore*" getConsoleInput $maxOreCols // check for id10t error on col numbers // $fuelCols is in the incProPlanetInfo include so we use it // by calling $incProPlanetInfo~fuelCol if ($maxOreCols < $incProPlanetInfo~fuelCol) echo ansi_12 "**You have more cols than that now*" halt else // see how many cols we need to get to target setVar $maxOreCols ($maxOreCols - $incProPlanetInfo~fuelCol) end // get sector from qStats for our warp back setVar $cs $incProQstats~stats[SECT] getDistance $toTerra $cs "1" getDistance $fromTerra "1" $cs // get ore required for trip to and from (single ship) setVar $oreReq (($toTerra + $fromTerra) * 3) // determine what the number of cols per load setVar $load ($incProQStats~stats[HLDS] - $oreReq) setVar $deliveredCols 0 while ($deliveredCols < $maxOreCols) // assuming SXX port in sector send "pt" $oreReq "**0* 0* " if ($incProQstats~stats[ALN] > 999) // jumping back without verifying tWarp lock, just might fuse. send "m 1* yy lt*m " $cs "* y y l " #8 $incProPlanetInfo~pNum "* snl1*q" else halt # need a red jump sector and move to terra end add $deliveredCols $load end halt include "proinc\incproQstats" include "proinc\incProPlanetInfo" # end of main script ------------------------------------------------------ // the included file(seperate)in the incPro folder named incProQstats.ts :qStats setVar $statsLine "" send "/" :slash setTextLineTrigger qstatsDone :qstatsDone "Ship" setTextLineTrigger 179 :179 #179 pause :179 setVar $statsLine $statsLine & currentline setTextLineTrigger 179 :179 #179 pause :qstatsdone killtrigger 179 setVar $statsLine $statsLine & currentline stripText $statsLine "," replaceText $statsLine #179 " " getword $statsLine $qStatsWord 1 getword $statsLine $qStatsVal 2 setVar $wordPointer 1 while ($qStatsWord <> 0) upperCase $qStatsWord setVar $stats[$qStatsWord] $qStatsVal add $wordPointer 2 getword $statsLine $qStatsWord $wordPointer getword $statsLine $qStatsVal ($wordPointer + 1) end return // returns the following in uppercase // "Sect Turns Creds Figs Shlds Hlds Ore Org Equ Col Phot Armd Lmpt GTorp TWarp // "Clks Beacns AtmDt Crbo EPrb MDis PsPrb PlScn LRS Aln Exp Corp Ship" |
|
| Author: | Kaus [ Fri Nov 25, 2011 10:56 pm ] |
| Post subject: | Re: Includes |
That is what I was looking for thank you for the example. Now I need a reason to write includes, im curious if theres any speed degredationif your calling a function vs calling a variable. I assume there would be, any insight? |
|
| Author: | Mongoose [ Sat Nov 26, 2011 2:57 am ] |
| Post subject: | Re: Includes |
Interesting... so in nerd terms, the tilde is a scoping operator and the include name functions as a namespace. I didn't know TWX was that sophisticated. |
|
| Page 1 of 1 | All times are UTC - 5 hours |
| Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |
|