View unanswered posts | View active topics It is currently Tue Apr 21, 2026 5:44 pm



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

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post Re: To Include, or not Include
Lone, when I said append... I meant that's where I tend to put all of my includes (at the bottom) and just said "append" because that's what I'm used to. It probably includes at the include statement.

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


LOL, a little bit of structure can fix a lot of that. As EP said, if you put something like....

Code:
# -----------------
# I should never get here!
halt
# -----------------


At the top/bottom of your include, it does stop that. Also better macros can really prevent the accidental warp offs in most cases, along with good indents to help you catch where a return should be... :-)

The reason I use includes is extensibility. Copy-paste works, but what if you figure out a better way to do something? Or... ick, a serious bug? Going thru each script that uses your code and fixing it is a real pain in the butt. This way I can make a single fix and fix them all.

Quote:
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.


*nod* Includes are included during the compilation run, not during execution. Makes sense to me.

For those that are cross-eyed...

A .TS file is a text file. TWXproxy can't understand text by itself, so it first makes a call to the compiler where the .TS file is made into a kind of processed bytecode. That bytecode is then read by TWXproxy. Includes are handled in the first run, along with some syntax checking and a few other things. But the actual code itself is handled during execution.

Quote:
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.


The problem then becomes trigger execution. Because triggers are gotos, and not gosubs, you can't control them so neatly. Sometimes I need triggers that sit around in the background and if they execute I need it to pass back to the main block-level so it can finish handling (ie: kill any other active triggers, then do something important).

One such example would be an adj torper. If someone hits a fig outside of the zone, it probably needs to reset the trigger (can be done internally to the include) but what if I don't want it to just reset and keep sitting? What if I want the same include to be able to shut itself off and turn on a pwarp torper? Ie: include-level triggers that need to be able to do things at the main-level code?

That's where callback handlers come into play. They get used in lower-level languages all the time, the windows API is full of them.

It's basically:
MyRoutine(var1ptr, var2ptr, callbackptr)

When the command runs, it grabs the vars from the 2 ptrs, then will callback when it's done. A very common example is error handling, you can setup an error handling callback to case out the problem and terminate or reset as needed.

If you can find a way to do that w/ triggers without resorting to this, by all means do tell. =)

_________________
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 3:28 pm
Profile ICQ WWW
Commander
User avatar

Joined: Wed May 03, 2006 2:00 am
Posts: 1722
Location: USA
Unread post Re: To Include, or not Include
LoneStar wrote:

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.


I do this with my quickstats routine to solve a few issues.


script 1
processin 1 "HELLO"

script2
settextlinetrigger qss1 :chk1 "HELLO"



This lets you handshake between scripts

_________________
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 5:22 pm
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
Singularity wrote:
Lone, when I said append... I meant that's where I tend to put all of my includes (at the bottom) and just said "append" because that's what I'm used to. It probably includes at the include statement.


Didn't mean to insinuate anything, just wanted to add a contextual 'converse' in my qustion to E.P. Thanks for your insite, it's much appreciated.

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


Fri Jan 11, 2008 5:44 pm
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
Parrothead wrote:
LoneStar wrote:

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.


I do this with my quickstats routine to solve a few issues.


script 1
processin 1 "HELLO"

script2
settextlinetrigger qss1 :chk1 "HELLO"

This lets you handshake between scripts


Yeah. like having one script analyze Gridding activity, and direct an attack script on which mode to switch into... that kind of stuff.. :wink:

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


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

Who is online

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