View unanswered posts | View active topics It is currently Sun Apr 19, 2026 2:48 pm



Reply to topic  [ 10 posts ] 
 Includes...can we get some tips? 
Author Message
Lieutenant Commander
User avatar

Joined: Sun Jan 29, 2006 3:00 am
Posts: 800
Location: Iowa
Unread post Includes...can we get some tips?
ok, here is my code problem in a nutshell:
Code:
:WorldTrade
  sys_check
  setVar $Move~CheckSub :WorldTrade~Sub_MoveCheck


This is lines 30-33 of the worldtrade include that comes with twx. I kept the 'sys_check' because it is a side puzzler, I'm assuming a remnant from an older version of twx?

My main question is with includes and the ~ key, which is not even alluded to in the include description in the script reference. I'm assuming that the above is assigning an address (:WorldTrade~Sub_MoveCheck) to a variable. So the variable $CheckSub in the Move include is now :WorldTrade, an address in the Sub_MoveCheck subroutine?

I guess I just want a better reference for INCLUDE than:

INCLUDE scriptname

Description:

This macro will include the code from another script or pack2 include file during compilation.

Example:

include "includemove"

_________________
#+++
The early bird may get the worm, but the second mouse gets the cheese.
#---


Fri May 27, 2011 6:04 am
Profile ICQ YIM
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post Re: Includes...can we get some tips?
Crosby wrote:
ok, here is my code problem in a nutshell:
Code:
:WorldTrade
  sys_check
  setVar $Move~CheckSub :WorldTrade~Sub_MoveCheck


This is lines 30-33 of the worldtrade include that comes with twx. I kept the 'sys_check' because it is a side puzzler, I'm assuming a remnant from an older version of twx?

My main question is with includes and the ~ key, which is not even alluded to in the include description in the script reference. I'm assuming that the above is assigning an address (:WorldTrade~Sub_MoveCheck) to a variable. So the variable $CheckSub in the Move include is now :WorldTrade, an address in the Sub_MoveCheck subroutine?

I guess I just want a better reference for INCLUDE than:

INCLUDE scriptname

Description:

This macro will include the code from another script or pack2 include file during compilation.

Example:

include "includemove"


the syscheck is a remnant from older TWX's.

when workign with Includes, a routine in one Include file may need the result(s) from another Include file. The safest way to pass variables from one include to another is the method you quoted above. It is possible for one include to access variables directly from another 'Include' file. It's a good idea to think of the Main file as the controller, sending tasks to routines, and sending the variable-results as required. If your Includes start accessing variables directly from Include to Include.. debugging will become a nightmare.

In terms of Memory. :WorldTrade~CheckSub and say :Haggle~CheckSub, are two independant variables. In much the same fashion as:

SetVar CheckSub1 "Good"
SetVar CheckSub2 "No Good"

varabiles are seperate and independant. The Tilde '~' Differentiates between which 'CheckSub' your working with. Remember, that when the script is compiled, the code from all files are placed into one contiguous segment/file.

A good tip I learned from Mind Dagger: Keep your Includes at the bottom of the main file. TWX works Top-Down when searching for Labels (beit a Goto or Gosub). Keep your most critical routines as close to the top as possible.

...basic template I usually work with:
Code:
Gosub :_STARTUP_


  HALT
:_STARTUP_
  #do initial variable settings, prompt checks etc.
  gosub :QuickStats~Qstats
  Waiton "Turns"
  #Includes can make debugging soo much easier
  #if you were to press: $STV and then QuickStats, at this point
  #will see a wonderful list of all the QuickStats~ variables.
  Echo "Press / to continue*"
  RETURN

Include "c:\twx\scripts\Parser.ts"
Include "c:\twx\scripts\QuickStats.ts"

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


Fri May 27, 2011 6:47 am
Profile ICQ YIM
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post Re: Includes...can we get some tips?
I only have time for a quick answer now, but ask further questions.

In TWX, when you include a file within your main file, you are essentially copy/pasting the contents of that include file into your main file. Got it?

This could create problems though because $variable names and :routine names might conflict. To avoid this, TWX basically renames all variables and headers that were in the include by prepending "includename~" to them. So if you had an include called "ep_include.ts", and in it you had a variable "$holds" and a header ":figrefresh", these would become "$ep_include~holds" for the variable and ":ep_include~figrefresh" for the header, all still within a single main script.

Code within an include can reference variables and headers within the calling or main script by using a blank include name, as in "$~variablename" and ":~headername". However, this isn't really advisable. The caller-include relationship should be:
1. the calling script sets any necessary variables in the include script (passes in variables).
2. the calling script gosubs a header/routine in the include.
3. the include returns after doing whatever
4. the calling script checks the value of variables in the include for the results (returns a value).

Now, please test this, as I could be wrong and haven't used includes in a while.

+EP+

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


Fri May 27, 2011 11:27 pm
Profile WWW
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post Re: Includes...can we get some tips?
I've had problems with that and saveVar tho. I had a routine that would exit out, pull the * stats, and import them into a file. Before the file, I was trying to save to variables. I couldn't saveVar from a routine and loadVar from main, it wouldn't load the right var.

_________________
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 May 27, 2011 11:53 pm
Profile ICQ WWW
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post Re: Includes...can we get some tips?
Singularity wrote:
I've had problems with that and saveVar tho. I had a routine that would exit out, pull the * stats, and import them into a file. Before the file, I was trying to save to variables. I couldn't saveVar from a routine and loadVar from main, it wouldn't load the right var.



This is what I use to help give the system time to 'catch up'

Code:
:_SLEEP_
SetDellayTrigger   Sleeper  :Sleeper  10
Pause
:Sleeper
KillTrigger Sleeper
Return


Also handy for breaking out of time intensive routines. You can actually $SX, no problem

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


Sat May 28, 2011 12:49 am
Profile ICQ YIM
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post Re: Includes...can we get some tips?
LoneStar wrote:
This is what I use to help give the system time to 'catch up'


It wasn't a matter of time, it was that variables read via loadVar don't translate $~var as $var. They're treated as two different variables.

_________________
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


Sat May 28, 2011 12:59 am
Profile ICQ WWW
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post Re: Includes...can we get some tips?
Singularity wrote:
LoneStar wrote:
This is what I use to help give the system time to 'catch up'


It wasn't a matter of time, it was that variables read via loadVar don't translate $~var as $var. They're treated as two different variables.


Yeah. 'time' was bit of a misnomer. Should have said 'free the CPU'. I'm sure that if you tried a delay, it would resolve.

[Edit] 10ms would be too quick. A minimum of 100ms would give the CPU enough opportunity to do it's job

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


Sat May 28, 2011 1:22 am
Profile ICQ YIM
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post Re: Includes...can we get some tips?
LoneStar wrote:
Yeah. 'time' was bit of a misnomer. Should have said 'free the CPU'. I'm sure that if you tried a delay, it would resolve.


No, it wouldn't. I'm talking about saveVar, then later, many hours or days later, doing a loadVar. The problem isn't a matter of timing or CPU, it's a matter of variable name resolution.

_________________
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


Sat May 28, 2011 3:13 am
Profile ICQ WWW
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post Re: Includes...can we get some tips?
Singularity wrote:
No, it wouldn't. I'm talking about saveVar, then later, many hours or days later, doing a loadVar. The problem isn't a matter of timing or CPU, it's a matter of variable name resolution.


Oops. Sorry. Your original response gave me the impression that the problem occured at run time.

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


Sat May 28, 2011 3:23 am
Profile ICQ YIM
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post Re: Includes...can we get some tips?
LoneStar wrote:
Oops. Sorry. Your original response gave me the impression that the problem occured at run time.


Well technically it does, everything happens at run-time. But it's really an issue of what's getting written to, and read from, the .cfg 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
Image


Sat May 28, 2011 3:26 am
Profile ICQ WWW
Display posts from previous:  Sort by  
Reply to topic   [ 10 posts ] 

Who is online

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