View unanswered posts | View active topics It is currently Thu Apr 23, 2026 6:28 am



Reply to topic  [ 9 posts ] 
 setVar, saveVar, includes 
Author Message
Ensign
User avatar

Joined: Tue Jul 21, 2009 2:37 pm
Posts: 241
Location: Ottawa, Canada
Unread post setVar, saveVar, includes
I thought I was starting to understand twx scripting, but I think I'm still missing some important info. Can anyone tell me what's wrong with this (i.e. why the output says '0' instead of 'testing123'?



scripts/test_main.ts:
--------------------------------------------------------------------------
include "test_vars.ts"
loadVar $testVar
echo "*Loaded testVar from main is " &$testVar& "*"
halt
--------------------------------------------------------------------------

scripts/test_vars.ts:
--------------------------------------------------------------------------
setVar $testVar "testing123"
saveVar $testVar
echo "* saved testVar as " &$testVar& "*"
--------------------------------------------------------------------------

output:
--------------------------------------------------------------------------

Loading and compiling script: scripts\test_main.ts

Citadel command (?=help)
saved testVar as testing123

Loaded testVar from main is 0

Script terminated: scripts\test_main.ts

--------------------------------------------------------------------------


I thought saveVar always associated with the current twx db, so it doesn't matter where I access it as long as it's the same db?

It works if I call it $test_vars~testVar from main, but the var is saved, so why do I have to reference it like that? Does saveVar prepend the filename to the varname??


Sat Sep 12, 2009 10:46 am
Profile
Ensign
User avatar

Joined: Tue Jul 21, 2009 2:37 pm
Posts: 241
Location: Ottawa, Canada
Unread post Re: setVar, saveVar, includes
If i stick a pause before the halt in test_main, and then dump vars with "test" in the name, i get the following.

--------------------------------------------------
"$TESTVAR" = "0"
"saved testVar as testing123
"$TEST_VARS~$3" = "testing123
"$TEST_VARS~TESTVAR" = "testing123"
--------------------------------------------------

A couple questions...

- Where the heck does $TEST_VARS~$3 come from, and why are there two dollar signs in the name? I read somewhere that there should be only one dollar sign, in the first part of the composite name?

- Where are the closing quotations in the second and third lines of the dump?

- Why is $TESTVAR = 0 if I called saveVar $testVar?


Sat Sep 12, 2009 11:11 am
Profile
Ensign
User avatar

Joined: Tue Jul 21, 2009 2:37 pm
Posts: 241
Location: Ottawa, Canada
Unread post Re: setVar, saveVar, includes
Ok, I guess I see why testvar = 0... include doesn't execute the file, like EP was saying somewhere... but now I'm really confused about the other two questions..


Sat Sep 12, 2009 12:10 pm
Profile
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post Re: setVar, saveVar, includes
Hotblack Desiato wrote:
Ok, I guess I see why testvar = 0... include doesn't execute the file, like EP was saying somewhere... but now I'm really confused about the other two questions..


Replace your test_main.ts with the following:

# test_main.ts #
include "test_vars.ts"
# prepending the saveVar variable from the include with the include name
loadVar $test_Vars~testVar
echo "*Loaded testVar from main is " $test_Vars~testVar "*"
halt

--------------------------------

If you look in \twx\data you will find a .cfg file with the same name as your gamename that you used in TWX's setup. You can view the SaveVars there.

_________________
               / Promethius / Enigma / Wolfen /

"A man who has no skills can be taught, a man who has no honor has nothing."


Sat Sep 12, 2009 2:03 pm
Profile ICQ
Ensign
User avatar

Joined: Tue Jul 21, 2009 2:37 pm
Posts: 241
Location: Ottawa, Canada
Unread post Re: setVar, saveVar, includes
Thank you Promethius... that data file is valuable information.

So I guess when I savevar from an include, the include's filename is prepended... I didn't realize that - seems a bit strange to me, because an included file could also be a stand-alone. I guess it makes sense.

Any insight on the extra $ or the missing " in the var dump? Are those just minor bugs in twx?


Sat Sep 12, 2009 2:11 pm
Profile
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post Re: setVar, saveVar, includes
Hotblack Desiato wrote:
Thank you Promethius... that data file is valuable information.

So I guess when I savevar from an include, the include's filename is prepended... I didn't realize that - seems a bit strange to me, because an included file could also be a stand-alone. I guess it makes sense.


lol, it doesn't make sense to me. EP can better explain exactly what includes do in regard to data - I just do whatever I have to to get my script going. Sometimes it isn't the best way, or even remotely good practice, but they usually end up doing what I want them to.

_________________
               / Promethius / Enigma / Wolfen /

"A man who has no skills can be taught, a man who has no honor has nothing."


Sat Sep 12, 2009 2:19 pm
Profile ICQ
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post Re: setVar, saveVar, includes
Hotblack Desiato wrote:
Thank you Promethius... that data file is valuable information.

So I guess when I savevar from an include, the include's filename is prepended... I didn't realize that - seems a bit strange to me, because an included file could also be a stand-alone. I guess it makes sense.

Any insight on the extra $ or the missing " in the var dump? Are those just minor bugs in twx?


Not sure on the extra $ as I did not see that in my var dump. The missing " may be the result of setting a var = "something*" -- the * would probably cause the ending quote to dissapear. You might want to test that.

_________________
               / Promethius / Enigma / Wolfen /

"A man who has no skills can be taught, a man who has no honor has nothing."


Sat Sep 12, 2009 2:22 pm
Profile ICQ
Ensign
User avatar

Joined: Tue Jul 21, 2009 2:37 pm
Posts: 241
Location: Ottawa, Canada
Unread post Re: setVar, saveVar, includes
Promethius wrote:
lol, it doesn't make sense to me. EP can better explain exactly what includes do in regard to data - I just do whatever I have to to get my script going. Sometimes it isn't the best way, or even remotely good practice, but they usually end up doing what I want them to.


Yeah, I was trying to stay away from getting into the habit of doing things that way...

XIde's documentation doesn't seem to cover stuff like referencing included vars and subs. Is there more documentation somewhere? I think the only place I know of that even mentions the ~ operator is this forum.


Sat Sep 12, 2009 2:33 pm
Profile
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post Re: setVar, saveVar, includes
Hotblack Desiato wrote:
Promethius wrote:
lol, it doesn't make sense to me. EP can better explain exactly what includes do in regard to data - I just do whatever I have to to get my script going. Sometimes it isn't the best way, or even remotely good practice, but they usually end up doing what I want them to.


Yeah, I was trying to stay away from getting into the habit of doing things that way...

XIde's documentation doesn't seem to cover stuff like referencing included vars and subs. Is there more documentation somewhere? I think the only place I know of that even mentions the ~ operator is this forum.


Documentation is pretty slim in regard to TWX. EP is setting up a site that will help, and Thrawn has information on his site (outpost-4.com/tradewars). NazHaz.com has some information - check the twcabal link and Sing's macro examples. The macros are not exactly TWX, but knowing how to put a string together for TWX to output is extremely important IMHO. Bad things can happen when your send command spews out game commands w/o handling different situations.

_________________
               / Promethius / Enigma / Wolfen /

"A man who has no skills can be taught, a man who has no honor has nothing."


Sat Sep 12, 2009 11:44 pm
Profile ICQ
Display posts from previous:  Sort by  
Reply to topic   [ 9 posts ] 

Who is online

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