www.ClassicTW.com
http://classictw.com/

How do I access M()MBot variables from another script?
http://classictw.com/viewtopic.php?f=15&t=33950
Page 1 of 1

Author:  Micro [ Tue Apr 23, 2013 1:00 pm ]
Post subject:  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"

Author:  Helix [ Tue Apr 23, 2013 6:43 pm ]
Post subject:  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

Author:  Micro [ Tue Apr 23, 2013 7:17 pm ]
Post subject:  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.

Author:  SupG [ Tue Apr 23, 2013 7:56 pm ]
Post subject:  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.

Author:  Helix [ Wed Apr 24, 2013 12:32 am ]
Post subject:  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

Author:  Micro [ Wed Apr 24, 2013 8:56 am ]
Post subject:  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.

Author:  SupG [ Wed Apr 24, 2013 1:38 pm ]
Post subject:  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.

Author:  Micro [ Wed Apr 24, 2013 2:59 pm ]
Post subject:  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.

Author:  Astrochimp [ Mon Sep 30, 2013 11:15 am ]
Post subject:  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

Author:  Kaus [ Tue Oct 01, 2013 7:23 am ]
Post subject:  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.

Author:  Astrochimp [ Tue Oct 01, 2013 10:06 am ]
Post subject:  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

Author:  ElderProphet [ Thu Oct 03, 2013 10:42 pm ]
Post subject:  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.

Author:  Astrochimp [ Thu Oct 03, 2013 11:12 pm ]
Post subject:  Re: How do I access M()MBot variables from another script?

Oh shoot that's useful! I did not know that, thanks EP!

Author:  Micro [ Fri Oct 04, 2013 10:35 am ]
Post subject:  Re: How do I access M()MBot variables from another script?

Thanks, That all makes sense now...

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