www.ClassicTW.com
https://mail.black-squirrel.com/

referencing included subs
https://mail.black-squirrel.com/viewtopic.php?f=15&t=23862
Page 1 of 1

Author:  Hotblack Desiato [ Thu Oct 22, 2009 5:43 pm ]
Post subject:  referencing included subs

So I do something like this from a script in the twx folder (c:\twx) that I load through the twx in-game script menu ($ssScriptname):

Code:
include "c:/twx/scripts/hd_include/util.ts"
gosub :util~subname


And then in util.ts I have something like this:
Code:
:subname
  echo ansi_15 "did some stuff"
return


but I always get a fatal run-time error when it's time to execute the sub... it can't find sub "util~subname".

Any ideas? I hate including all my subs explicitly... feels ridiculous.

Author:  Singularity [ Thu Oct 22, 2009 5:58 pm ]
Post subject:  Re: referencing included subs

Includes should be at the bottom, and put a halt before hand so they aren't called during runtime. Basically an include just takes the block of code and sticks it in the file. Also, your path might be a problem. You don't need to specify all of that, includes are assumed to be in dir of the calling script unless otherwise specified (hence why you should compile complex scripts before passing them out).

Try this:

Code:
gosub :util~subname

# -------
halt
# -------
include "hd_include/util.ts"
# -------

Author:  Hotblack Desiato [ Sat Oct 24, 2009 12:01 pm ]
Post subject:  Re: referencing included subs

Thanks for the reply... still having problems. Here's the input and output:

c:\TWX\scripts\test_ExternalSub.ts
Code:
echo ansi_8 & "**.....     Calling TestExternalSub...**"
gosub :TestExternalSub~SubName
halt
include "hd_include/TestExternalSub.ts"


c:\TWX\scripts\hd_include\TestExternalSub.ts
Code:
:SubName
    echo ansi_15 & "**!!!!   TestExternalSub did some stuff.**"
return


output after sending "$sstest_ExternalSub" to twx

Quote:
Loading and compiling script: scripts\test_ExternalSub.ts

Command [TL=00:00:00]:[12085] (?=Help)? :

..... Calling TestExternalSub...

Script run-time error in 'TEST_EXTERNALSUB.TS': Goto label not found 'TESTEXTERN
ALSUB~SUBNAME', line 3

Script terminated: scripts\test_ExternalSub.ts


Pulling out my hair over this...

Author:  Singularity [ Sat Oct 24, 2009 12:46 pm ]
Post subject:  Re: referencing included subs

Is that the entire actual script? I don't see anything wrong at first glance... maybe it's the case, try all lowercase?

Are you sure the actual .ts is there in the includes, it's not .ts.txt or something like notepad is famous for?

Author:  Helix [ Sat Oct 24, 2009 12:57 pm ]
Post subject:  Re: referencing included subs

include "scripts\hd_include\TestExternalSub.ts" ?

Helix

Author:  ElderProphet [ Sat Oct 24, 2009 1:07 pm ]
Post subject:  Re: referencing included subs

The problem is that you have the file extension in the include statement. Rather, it should read:
include "hd_include\TestExternalSub"

Hope you have some hair left ;)

+EP+

Author:  Singularity [ Sat Oct 24, 2009 1:32 pm ]
Post subject:  Re: referencing included subs

Really? I reference scripts like that all the time in an include.

Here's a snippet from a script...

Code:
# Update figs
gosub :sector_fun~update_figs
waitFor "Sub-space comm-link terminated"

# Update limps?
if ($dpcr_require_limps = "Yes")
    send "'     *"
    gosub :sector_fun~update_limps
    waitFor "Sub-space comm-link terminated"
end


And later...

Code:
# -------------------------------------------------------------------
# Includes
include "dny_includes\sector_fun.ts"
include "dny_includes\fast_twarp.ts"
include "dny_includes\cn_settings.ts"
include "dny_includes\quickstats.ts"
include "dny_includes\getcourse.ts"
# -------------------------------------------------------------------


See, .ts =)

Author:  Hotblack Desiato [ Sat Oct 24, 2009 1:42 pm ]
Post subject:  Re: referencing included subs

Yeah, the ts didn't make a difference, neither did Helix's suggestion, and neither did the lowercase...

Sing, yes those are the entire files. I've just tried saving all files with lowercase names, and changing the sub name and sub call and include statement to all lowercase.. same result...

Thanks for the help everyone... but still losing hair.

Oh yeah and Sing I don't use notepad... My editor's title bar shows the entire filepath of the file I'm editing, so I know the paths and filenames are correct.

Author:  Hotblack Desiato [ Sat Oct 24, 2009 1:46 pm ]
Post subject:  Re: referencing included subs

It's working now!

replaced the forward slash in include statement with a backslash..

coulda sworn we were spose to use forward slashes...

Author:  Singularity [ Sat Oct 24, 2009 3:53 pm ]
Post subject:  Re: referencing included subs

Oh yeh, twxproxy is slash sensitive. Forgot about that. Huh

Good to know.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/