View unanswered posts | View active topics It is currently Wed Apr 17, 2024 7:12 pm



Reply to topic  [ 13 posts ] 
 Passing a variable in a include 
Author Message
Gameop
User avatar

Joined: Tue Nov 19, 2002 3:00 am
Posts: 1050
Location: USA
Unread post Passing a variable in a include
I have been unable to pass a declared variable in a include, wondering if I'm missing a trick?

While I'm on the subject do we really have to declare the root in the below example?

Where root may be different I had hoped ~/ would suffice.

e.g.
Code:
getFileList $list "twx\include" & "\*.ts"
setvar $idx 1
While ($idx <= $list)
   Include "C:\TWX\include\" & $list[$idx]
   add $idx 1
end


Returns "Script compilation error: Unable to process include file 'C:\TWX\include\" & $LIST[$IDX]', line X (TEST.TS)"

I'm considering writing the GetFileList to a cfg with pre/post pend and calling it that way, just want to make sure I'm not missing a trick to passing it natively.

_________________
Dark Dominion TWGS
Telnet://twgs.darkworlds.org:23
ICQ#31380757, -=English 101 pwns me=-
"This one claims to have been playing since 1993 and didn't know upgrading a port would raise his alignment."


Tue Nov 17, 2015 10:49 am
Profile ICQ
Immortal Op
User avatar

Joined: Fri Jun 25, 2010 6:33 am
Posts: 257
Location: Sydney Australia
Unread post Re: Passing a variable in a include
you need to give the include command the path if the include file is not in the script folder. normally the include files are kept in the scripts\include folder so you should find that a relative address from the script folder will do, such as ..

include include\includefilename.ts.


to pass an include variable, assign it using the include file variables full address. as in ..

SetVar $Z_Lib~scriptname $scriptname

where $Z_Lib.ts is the include file name (leave out the .ts extension) and scriptname is the variable inside the include. The tilde character is necessary. The $scriptname variable is the variable being passed.

_________________
Teamspeak3: 60.242.57.40:9987
Z-Bot does my dirty work!


Tue Nov 17, 2015 4:30 pm
Profile ICQ
Gameop
User avatar

Joined: Tue Nov 19, 2002 3:00 am
Posts: 1050
Location: USA
Unread post Re: Passing a variable in a include
Archy wrote:
you need to give the include command the path if the include file is not in the script folder.


Archy, thanks for the response. What I'm trying to accomplish is passing the include filename as partially a variable in the script without the need for individual declaration. Thereby allowing flexibility for that folder and automatic creation of include file library at run-time. I could dump the getFileList to a document then read off that but I was hoping I could do so without that added step.

e.g. the above code vs.

include script\include.ts
include c:\twx\script\include.ts
include script\someotherinclude.ts

_________________
Dark Dominion TWGS
Telnet://twgs.darkworlds.org:23
ICQ#31380757, -=English 101 pwns me=-
"This one claims to have been playing since 1993 and didn't know upgrading a port would raise his alignment."


Wed Nov 18, 2015 10:20 am
Profile ICQ
Ambassador
User avatar

Joined: Wed Apr 20, 2011 1:19 pm
Posts: 2559
Location: Oklahoma City, OK 73170 US
Unread post Re: Passing a variable in a include
Since include is a compiler directive, I don't think you can pass the file name as a variable, or use it inside a loop. The script isn't actually running at compile time when the include files are added.

_________________
Regards,
Micro

Website: http://www.microblaster.net
TWGS2.20b/TW3.34: telnet://twgs.microblaster.net:2002

ICQ is Dead Jim! Join us on Discord:
https://discord.gg/zvEbArscMN


Wed Nov 18, 2015 12:34 pm
Profile ICQ YIM WWW
Immortal Op
User avatar

Joined: Fri Jun 25, 2010 6:33 am
Posts: 257
Location: Sydney Australia
Unread post Re: Passing a variable in a include
Micro wrote:
Since include is a compiler directive, I don't think you can pass the file name as a variable, or use it inside a loop. The script isn't actually running at compile time when the include files are added.


Yea I think you are right..

Sorry Kaus.. now I get what you are trying to do.. Micro is right (I think).
If you REALLY want to automate adding all include files in the folder, you might need to write a batch file to add the include commands to the end of the script before compile. You could put the actual compile command in the batch file too. (make it a 1 click process).

_________________
Teamspeak3: 60.242.57.40:9987
Z-Bot does my dirty work!


Wed Nov 18, 2015 4:25 pm
Profile ICQ
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1396
Location: Canada
Unread post Re: Passing a variable in a include
Hi there!

You could do something similar to what my LSECT (Lonestar's Express Colonize & Tow), script does: At the end of the main script is code that sets variables in a long variable-string, and then outputs a new script file (after deleting any existing version), and then loads that Newley generated script.

Or, just bug EP, for a newer version of TWX that will allow global variables. I would probably return for that!!

_________________
----------------------------
-= QUANTUM Computing 101: 15 = 3 x 5 ... 48% of the time.
-= There are 10 types of people in the world: Those that understand Binary and those who do not
-= If Oil is made from Dinosaurs, and Plastic is made from Oil... are plastic Dinosaurs made from real Dinosaurs?
-= I like to keep my friends and my enemies rich, and wait to see which is which - Tony Stark (R.I.P.)


Thu Nov 19, 2015 4:40 am
Profile ICQ YIM
Gameop
User avatar

Joined: Tue Nov 19, 2002 3:00 am
Posts: 1050
Location: USA
Unread post Re: Passing a variable in a include
LoneStar wrote:
Hi there!

You could do something similar to what my LSECT (Lonestar's Express Colonize & Tow), script does: At the end of the main script is code that sets variables in a long variable-string, and then outputs a new script file (after deleting any existing version), and then loads that Newley generated script.

Or, just bug EP, for a newer version of TWX that will allow global variables. I would probably return for that!!


Hey LS,

Interesting approach, I read your TS and I like the :WriteBehind approach as a potential fix. I've tried mostly everything else so far (variations of calling it natively as well as writing to a subscript) none worked and I guess logically they shouldn't since it's a compile process (thxs micro didn't know that).

Anyways the intent here is to work in tandem with my MOM rewrite in that I would prefer that non-core bot functions are modular and therefor included vs. being standalone. With the caveat that if someone wants to add a function or improve exiting code they simply drag and drop (modify the cfg) and wala it's there at load-time. I guess I could write a similar function as yours to write the includes first first followed by the bulk of code and then reload with the correct folder includes. My concern being loop conditions.

I'll let you know how it goes, it may not be possible with the current TWX implementation natively but what fun would it be to not try :-)

Global variables would certainly make this easier.

_________________
Dark Dominion TWGS
Telnet://twgs.darkworlds.org:23
ICQ#31380757, -=English 101 pwns me=-
"This one claims to have been playing since 1993 and didn't know upgrading a port would raise his alignment."


Thu Nov 19, 2015 6:06 pm
Profile ICQ
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1131
Location: Augusta, GA
Unread post Re: Passing a variable in a include
It's late, and I'm not following what you're unable to do. Please, restate it with examples, and I'll try to advise.

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


Thu Nov 19, 2015 11:39 pm
Profile WWW
Gameop
User avatar

Joined: Tue Nov 19, 2002 3:00 am
Posts: 1050
Location: USA
Unread post Re: Passing a variable in a include
ElderProphet wrote:
It's late, and I'm not following what you're unable to do. Please, restate it with examples, and I'll try to advise.


Desired State: I would like to dynamically set "Includes" within a script via variable or externally created reference using the write command.

Purpose: Include list which can grow or shrink at run-time based on folder contents.

Example:
Code:
getFileList $list "twx\include" & "\*.ts"
setvar $idx 1
While ($idx <= $list)
   Include "C:\TWX\include\" & $list[$idx]
   add $idx 1
end


Issues and attempted variations:
I can't pass a created variable as part of the include declaration. (e.g. setVar $temp "C:\")

I can't reference a file which holds the include list. (e.g. calling list.txt which houses the include list)

Building the list via variable first then rebuilding the script causes loop conditions. I haven't completely discounted this variation yet, it seems to me this is plausible if I can manipulate the text better. (to remove the loop condition)

_________________
Dark Dominion TWGS
Telnet://twgs.darkworlds.org:23
ICQ#31380757, -=English 101 pwns me=-
"This one claims to have been playing since 1993 and didn't know upgrading a port would raise his alignment."


Fri Nov 20, 2015 12:08 pm
Profile ICQ
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1131
Location: Augusta, GA
Unread post Re: Passing a variable in a include
Ok, I copy now, thanks.

Let me unpack what the include directive does, and that may add some clarity.

Let's say you have an include file called logo.ts, and it includes one header and one variable, as follows:
Code:
setVar $myLogo "*EP haxorz TW"
:echoLogo
echo $myLogo
return
You have logo.ts saved in the include folder. Now, at the bottom of some script, you add the line: include "include\logo"
Effectively, that line is replaced with the following lines:
Code:
setVar $logo~myLogo "*EP haxors TW"
:logo~echoLogo
echo $logo~myLogo
return
So effectively, each line of the include file is copied to the calling script, and "logo~" is inserted after any : and $ symbols.

The compiled code of any running script can't be changed. You can add lines to a script and then launch it though, as discussed. I'll keep mulling it over. Global variables... for now the best bet is sector parameters, which takes several lines of code, but I'll put some thought into it during my next coding session.

In your example, you're trying to include an unknown list of scripts. Help me understand why. How can a calling script make use of include scripts that it doesn't know about? Or how can included scripts make use of other included scripts that aren't known ahead of time? What is the use case?

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


Sat Nov 21, 2015 11:19 pm
Profile WWW
Commander

Joined: Sun Feb 25, 2001 3:00 am
Posts: 1837
Location: Guam USA
Unread post Re: Passing a variable in a include
I think what he is trying to do is make another way to loop an include directory , so that the main script can use those scripts as internals.

Verse the current way , placing them in sub-folder to be be called.

I do not see why this technique is not good enough.

Vid

_________________
TWGS V2 Vids World on Guam Port 2002
Telnet://vkworld.ddns.net:2002
Discord @ DiverDave#8374
Vid's World Discord

Founding Member -=[Team Kraaken]=- Ka Pla

Image
Winners of Gridwars 2010
MBN Fall Tournament 2011 winners Team Kraaken
Undisputed Champions of 2019 HHT Just for showing up!

The Oldist , Longist Running , Orginal Registered Owner of a TWGS server :
Vids World On Guam


Sun Nov 22, 2015 8:38 pm
Profile WWW
Gameop
User avatar

Joined: Tue Nov 19, 2002 3:00 am
Posts: 1050
Location: USA
Unread post Re: Passing a variable in a include
ElderProphet wrote:
In your example, you're trying to include an unknown list of scripts. Help me understand why. How can a calling script make use of include scripts that it doesn't know about? Or how can included scripts make use of other included scripts that aren't known ahead of time?


Honestly when I embarked on seeing If I could do it. I had envisioned standardizing a include list that could be called by the main script while having a modular code that I could plop into any script I was working on without the need of a page long include list.
(code reduction, less housekeeping, add-on interface)

More I just wanted to see if it was possible vs. having a set of includes (current list) that you just copy and paste into various scripts. However that last sentence in your reply really kinda framed the more significant issue for me. Even if it is possible ,writing a script which also will check for new variables and define those variables prolly isn't something I'm going to write, assuming it's even possible.

_________________
Dark Dominion TWGS
Telnet://twgs.darkworlds.org:23
ICQ#31380757, -=English 101 pwns me=-
"This one claims to have been playing since 1993 and didn't know upgrading a port would raise his alignment."


Mon Nov 23, 2015 12:57 pm
Profile ICQ
Ambassador
User avatar

Joined: Wed Apr 20, 2011 1:19 pm
Posts: 2559
Location: Oklahoma City, OK 73170 US
Unread post Re: Passing a variable in a include
The downside it that all of your scripts would be much larger than necessary, because the entire include file becomes part of the compiled script. It would also increase compile time, but I don't think it would impact performance significantly when running.

_________________
Regards,
Micro

Website: http://www.microblaster.net
TWGS2.20b/TW3.34: telnet://twgs.microblaster.net:2002

ICQ is Dead Jim! Join us on Discord:
https://discord.gg/zvEbArscMN


Tue Nov 24, 2015 9:33 am
Profile ICQ YIM WWW
Display posts from previous:  Sort by  
Reply to topic   [ 13 posts ] 

Who is online

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