View unanswered posts | View active topics It is currently Thu Apr 18, 2024 6:04 pm



Reply to topic  [ 14 posts ] 
 How do I access M()MBot variables from another script? 
Author Message
Ambassador
User avatar

Joined: Wed Apr 20, 2011 1:19 pm
Posts: 2559
Location: Oklahoma City, OK 73170 US
Unread post How do I access M()MBot variables from another script?
How do I access M()MBot variables from another script?

Code:
Dumping all script variables containing 'mode'
> planet
Variable dump for script: C:\TW2002\TWXP3001\Scripts\@MomBot.cts

"$PLANET" = "3"

_________________
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 Apr 23, 2013 1:00 pm
Profile ICQ YIM WWW
Ambassador
User avatar

Joined: Wed Nov 12, 2008 8:57 am
Posts: 3554
Location: Long Beach, CA
Unread post Re: How do I access M()MBot variables from another script?
saveVar to save the variable in the .cfg file in twxproxy\data

loadVar to load the variable in the .cfg file in twxproxy\data

_________________
Helix
Do I really look like a guy with a plan? You know what I am? I'm a dog chasing cars.
Lest we forget
I had to ask myself WWSGD?


Tue Apr 23, 2013 6:43 pm
Profile WWW
Ambassador
User avatar

Joined: Wed Apr 20, 2011 1:19 pm
Posts: 2559
Location: Oklahoma City, OK 73170 US
Unread post Re: How do I access M()MBot variables from another script?
$PLANET is a M()MBOT Variable. I don't seem to be able to access it with loadVar.

_________________
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 Apr 23, 2013 7:17 pm
Profile ICQ YIM WWW
1st Sergeant

Joined: Wed Jan 23, 2002 3:00 am
Posts: 33
Unread post Re: How do I access M()MBot variables from another script?
I haven't done any TWX scripting in a LONG time, but I'm pretty sure if you want to use variables from another script, you'd have to include the source script into your own script and reference them that way.

I don't know anything about mombot either - so that's all I can help with.


Tue Apr 23, 2013 7:56 pm
Profile ICQ WWW
Ambassador
User avatar

Joined: Wed Nov 12, 2008 8:57 am
Posts: 3554
Location: Long Beach, CA
Unread post Re: How do I access M()MBot variables from another script?
Micro wrote:
$PLANET is a M()MBOT Variable. I don't seem to be able to access it with loadVar.

saveVar $Planet

loadVar $Planet

_________________
Helix
Do I really look like a guy with a plan? You know what I am? I'm a dog chasing cars.
Lest we forget
I had to ask myself WWSGD?


Wed Apr 24, 2013 12:32 am
Profile WWW
Ambassador
User avatar

Joined: Wed Apr 20, 2011 1:19 pm
Posts: 2559
Location: Oklahoma City, OK 73170 US
Unread post Re: How do I access M()MBot variables from another script?
Helix wrote:
Micro wrote:
$PLANET is a M()MBOT Variable. I don't seem to be able to access it with loadVar.

saveVar $Planet

loadVar $Planet


saveVar $Planet

loadVar $Planet

echo "-" $Planet "-"

results:

--

This is information I can not obtain, unless I had a script running when you landed on a planet. Since M()MBOT is always running, it maintains this information and stores it in the $Planet variable.

_________________
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 Apr 24, 2013 8:56 am
Profile ICQ YIM WWW
1st Sergeant

Joined: Wed Jan 23, 2002 3:00 am
Posts: 33
Unread post Re: How do I access M()MBot variables from another script?
You'd have to modify mombot's source code to run the saveVar command, then run loadVar from your script.


Wed Apr 24, 2013 1:38 pm
Profile ICQ WWW
Ambassador
User avatar

Joined: Wed Apr 20, 2011 1:19 pm
Posts: 2559
Location: Oklahoma City, OK 73170 US
Unread post Re: How do I access M()MBot variables from another script?
It turns out that M()MBOT is already saving the variable with saveVar. I have discovered that I can access it from the main file, but not from a Gosub inside an included file where I need it. So, in the main file:

loadVar $Planet
setVar $MyPlanet $Planet

...and then I can access $MyPlanet in the included gosub.

_________________
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 Apr 24, 2013 2:59 pm
Profile ICQ YIM WWW
Ensign
User avatar

Joined: Mon Dec 26, 2011 8:41 am
Posts: 206
Unread post Re: How do I access M()MBot variables from another script?
Micro wrote:
It turns out that M()MBOT is already saving the variable with saveVar. I have discovered that I can access it from the main file, but not from a Gosub inside an included file where I need it. So, in the main file:

loadVar $Planet
setVar $MyPlanet $Planet

...and then I can access $MyPlanet in the included gosub.


What actually happens is that the include file gets slapped into your main script when it is compiled, and all the names for variables and labels that were inside the include file get transformed to avoid collisions with other variables and labels.

So when you have
Code:
loadVar $Planet
in your include file, and say you reference that include file from your main script using
Code:
include "myInclude"
, then
Code:
loadVar $Planet
becomes
Code:
loadVar $myInclude~Planet


Mon Sep 30, 2013 11:15 am
Profile ICQ
Gameop
User avatar

Joined: Tue Nov 19, 2002 3:00 am
Posts: 1050
Location: USA
Unread post Re: How do I access M()MBot variables from another script?
Astro hit it on the head, you have to reference the script that has the variable you want to save and have actually saved it prior to loading it. If memory serves you can reference the variable specifically and individually if needed.

_________________
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 Oct 01, 2013 7:23 am
Profile ICQ
Ensign
User avatar

Joined: Mon Dec 26, 2011 8:41 am
Posts: 206
Unread post Re: How do I access M()MBot variables from another script?
Micro wrote:
So, in the main file:
loadVar $Planet
setVar $MyPlanet $Planet


Now that I look at it again, I don't see how the above works any better, and if it does work it means there's something I'm not understanding and I'd like to see the code. If you try to reference $MyPlanet, which is defined in the main script, from an included file, then when the main script is compiled, the included file gets pasted into the main script, and any $MyPlanet used in the included file becomes $includeFileName~MyPlanet.

The following should work.

in bot:
Code:
saveVar $Planet


In your script's main file:
Code:
loadVar $Planet
setVar $includeFileName~MyPlanet $Planet
gosub :includeFileName~subLabel
halt
#...
include "scripts/includeFileName.ts"


in scripts/includeFileName.ts:
Code:
:subLabel
echo "*passed planet is: " & $MyPlanet & "*"
return


Tue Oct 01, 2013 10:06 am
Profile ICQ
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1131
Location: Augusta, GA
Unread post Re: How do I access M()MBot variables from another script?
I haven't carefully read this thread, so forgive me if this post is off-topic. I wanted to add that an include can reference a variable in the calling script. I believe the syntax is $~callingscriptvariable
So if the main script has a variable $version, I believe an include can reference $~version.

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


Thu Oct 03, 2013 10:42 pm
Profile WWW
Ensign
User avatar

Joined: Mon Dec 26, 2011 8:41 am
Posts: 206
Unread post Re: How do I access M()MBot variables from another script?
Oh shoot that's useful! I did not know that, thanks EP!


Thu Oct 03, 2013 11:12 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: How do I access M()MBot variables from another script?
Thanks, That all makes sense now...

_________________
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


Fri Oct 04, 2013 10:35 am
Profile ICQ YIM WWW
Display posts from previous:  Sort by  
Reply to topic   [ 14 posts ] 

Who is online

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