View unanswered posts | View active topics It is currently Wed Apr 22, 2026 5:46 pm



Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
 To Include, or not Include 
Author Message
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post To Include, or not Include
Wondering how Includes work.

If the Main.ts file Includes a STATS.ts, and a LIB.ts; I realize that the LIB.ts cannot directly access the $STATS~Vars unless the Main.ts passes the info (ie: setVar $LIB~var $STATS~var). My question is, if the LIB.ts also includes the same STATS.ts (same file, same directory path), does TWXC actually include STATS.ts twice?

I started using Includes as a better way to manage larger projects, but at the same time want to be as efficient as I now how to be.

Thanks in advance

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


Thu Jan 10, 2008 4:09 pm
Profile ICQ YIM
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post Re: To Include, or not Include
In TWX proxy it's all compiled into a single file. Variables and routines are prefixed w/ the include name, but basically it's just attached to the bottom of the file. I believe you can access another include's data just fine, have you actually tried it?

Is the compiler smart enough to not include the same include twice... or would it mess something up? I don't know. You'll probably need to ask EP for that answer.

_________________
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 Jan 10, 2008 5:17 pm
Profile ICQ WWW
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post Re: To Include, or not Include
Tried again with a simpler file. seems to work now.. laff

Looking back I think I was trying to access variables in included files that wernt initalized (sub procedures hadn't been called), which makes sense.

Thanks

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


Thu Jan 10, 2008 6:52 pm
Profile ICQ YIM
Chief Warrant Officer
User avatar

Joined: Wed Jan 04, 2006 3:00 am
Posts: 136
Location: USA
Unread post Re: To Include, or not Include
Hmm, this is something I was confused about too. I didn't realize that including it once would allow all the pieces to call from the included subroutines. Good stuff.

MD


Thu Jan 10, 2008 10:43 pm
Profile
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post Re: To Include, or not Include
Little trivia...
goto :~blah

Calls to :blah in the main file. So you can create callback handlers for included triggers... which ends up being pretty useful as you expand your include usage.

_________________
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 Jan 11, 2008 12:30 am
Profile ICQ WWW
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post Re: To Include, or not Include
Wow. That is really kewl :D

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


Fri Jan 11, 2008 6:38 am
Profile ICQ YIM
Lieutenant

Joined: Fri Apr 05, 2002 3:00 am
Posts: 580
Location: USA
Unread post Re: To Include, or not Include
For the longest time I didnt use them and I would just have routines I use all the time stored somewhere then copy and paste it in.
Now I just pop in the include and it is there.

Includes are pretty cool but if you forget the return and other parts, you will be sent flying into space lol.

_________________
My scripts can be downloaded at http://www.grimytrader.com/.
Ore *****.
Even in my signature it's blocked out.


Fri Jan 11, 2008 8:24 am
Profile ICQ YIM
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post Re: To Include, or not Include
Wildstar wrote:
For the longest time I didnt use them and I would just have routines I use all the time stored somewhere then copy and paste it in.
Now I just pop in the include and it is there.


I use to do Same. Cut & Paste, and repeat. But I'm tired of hunting around hundreds of line of code.. leaving XXX's as bookmarks to Ctrl-F back to. Laff. Besides. a nifty feature of Includes is when debugging, TWX tell you which Line AND which Include the Error occured (Esp handy for those those pesky errors where a 'End' is missing.

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


Fri Jan 11, 2008 10:04 am
Profile ICQ YIM
Commander
User avatar

Joined: Wed May 03, 2006 2:00 am
Posts: 1722
Location: USA
Unread post Re: To Include, or not Include
Same thing over and over..includes are much handier than cut and paste.

Comms checks/prompt checks/saftey routines...etc etc.

Code:
#Parrothead Comms Controler Include
#=-=-=-=-=-=--=
:off
killalltriggers
setdelaytrigger 3off :offcomms 3000
setTexttrigger 1off :1off "Displaying all messages"
setTexttrigger 2off :2off "Silencing all messages"
send "|"
pause
:offcomms
killtrigger 3off
killTrigger 1off
killTrigger 2off
goto :off
:1off
killtrigger 3off
killTrigger 1off
killTrigger 2off
send "|"
:2off
killtrigger 3off
killTrigger 1off
killTrigger 2off
echo ANSI_3 "<<<" & ANSI_12 "Comm's Off" & ANSI_3 ">>>" ANSI_0
return
#=-=-=-=-=-=--=
:on
killalltriggers
setdelaytrigger 2on :oncomms 3000
setTexttrigger 3on :3on "Displaying all messages"
setTexttrigger 4on :4on "Silencing all messages"
send "|"
pause
:oncomms
killtrigger 2on
killTrigger 3on
killTrigger 4on
goto :on
:4on
killtrigger 2on
killTrigger 3on
killTrigger 4on
send "|"
:3on
killtrigger 2on
killTrigger 3on
killTrigger 4on
echo ANSI_3 "<<<" & ANSI_15 "Comm's On" & ANSI_3 ">>>" ANSI_0
return

_________________
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


Fri Jan 11, 2008 12:14 pm
Profile ICQ YIM
Chief Warrant Officer
User avatar

Joined: Wed Jan 04, 2006 3:00 am
Posts: 136
Location: USA
Unread post Re: To Include, or not Include
The only downside to includes I have seen at all is when you have a very large script (10000 lines or more - obviously doesn't happen often) that uses includes for a commonly called subroutine. I have seen a performance hit if subroutines are located at the bottom of a long script, and since includes essentially append them to the end this can cause a problem. One such subroutine that was causing a big speed drop with the bot was quikstats.

Not a problem most people would have though, since most scripts don't run long enough to make it matter. Includes certainly make updating your routines within all your scripts much more efficient, plus all the other benefits already stated.

MD


Fri Jan 11, 2008 12:39 pm
Profile
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post Re: To Include, or not Include
Mind Dagger wrote:
...and since includes essentially append them to the end this can cause a problem. One such subroutine that was causing a big speed drop with the bot was quikstats.



Not sure about that. I have include statements at the top and bottom of my scripts. Seems that if you put a include at the top, you need to use a 'goto' to skip over it.
Code:
#what I started doing
Goto :_START_
include "STATS.ts"
:_START_

#Code Here
halt
include "NonEssentialStuff.ts"


One idea I'm toying with is making use of the processin command. Having a Daemon type script running that waits for a call (via proprietary Tirggers), then signals back via a similar process. Like having customized Interrupts.

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


Fri Jan 11, 2008 1:13 pm
Profile ICQ YIM
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post Re: To Include, or not Include
Heh, here's my quote of MD:
"Some users experienced a performance hit when using my 25,000 line bot, but it's much better now that its only 12,000 lines."

I think the basics have been covered. I would discourage calls from an include to the calling script or to another include of the calling script though. If you find yourself doing that, there's likely a better technique you should use. Best practice would be setting an include's variables from the main routine, and calling subroutines that return. You might setup a $subroutine~result type variable that can be queried from the main script rather than letting an include set some variable in the main script. I can expand upon that if needed.

+EP+

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


Fri Jan 11, 2008 1:23 pm
Profile WWW
Chief Warrant Officer
User avatar

Joined: Wed Jan 04, 2006 3:00 am
Posts: 136
Location: USA
Unread post Re: To Include, or not Include
LoneStar wrote:
Code:
#what I started doing
Goto :_START_
include "STATS.ts"
:_START_

#Code Here
halt
include "NonEssentialStuff.ts"


One idea I'm toying with is making use of the processin command. Having a Daemon type script running that waits for a call (via proprietary Tirggers), then signals back via a similar process. Like having customized Interrupts.


Oh good.. Well dang I guess I will break down and start putting my stuff into includes again. Thanks Lone.

ElderProphet wrote:
Heh, here's my quote of MD:
"Some users experienced a performance hit when using my 25,000 line bot, but it's much better now that its only 12,000 lines."


11,800 thanks very much. :P
Heh


MD


Fri Jan 11, 2008 1:59 pm
Profile
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post Re: To Include, or not Include
LoneStar wrote:
Not sure about that. I have include statements at the top and bottom of my scripts. Seems that if you put a include at the top, you need to use a 'goto' to skip over it.
Code:
#what I started doing
Goto :_START_
include "STATS.ts"
:_START_

#Code Here
halt
include "NonEssentialStuff.ts"

I realize that this can be confusing, so let me attempt to clarify. Includes aren't executed... they're included. When you include a file, you aren't actually launching it. Includes can and probably should be listed at the top of the main script, for clarity. When you execute a script, TWX scans right away to see if any includes are specified. If there are, then it tokenizes the include's variables and :headers, essentially prepending "IncludeScriptName~" to these values. The very first line of that include could be HALT (and probably should be if it isn't intended for stand-alone use), and it will work fine.

I developed a habit of writing scripts for use as stand-alone scripts, or as includes. I would group a list of common routines together in a file for use as an include, then create a simple menu or prompt at the beginning (in case it's launched stand-alone) to allow access to any routines that are useful if called directly. The most important part though, is the documentation at the beginning of a script or include, defining it's calling conventions.

+EP+

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


Fri Jan 11, 2008 2:09 pm
Profile WWW
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post Re: To Include, or not Include
Okay. Does TWX include or 'stick-in' an Include more or less where you put the Include statment in the Main file?

To be a tad clearer: If I include STATS.ts at the top of the main file with code beneath, does TWX insert the STATS.ts at the very begining of the CTS, or as Sing indicated; TWX appends all includes at the end of the main TS ?

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


Fri Jan 11, 2008 2:58 pm
Profile ICQ YIM
Display posts from previous:  Sort by  
Reply to topic   [ 19 posts ]  Go to page 1, 2  Next

Who is online

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