[MD Tool] MD Control (Scripts can send vars to MD) v1.13a - 20Jan2010

The place to discuss scripting and game modifications for X³: Terran Conflict and X³: Albion Prelude.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

h2o.Ava
Posts: 317
Joined: Sun, 12. Oct 08, 04:04
x3tc

[MD Tool] MD Control (Scripts can send vars to MD) v1.13a - 20Jan2010

Post by h2o.Ava » Mon, 15. Nov 10, 02:30

Introduction
. . Currently Mission Director(MD) can start a script and pass arguments into the script while it is impossible for a Script Engine/Editor(SE) to directly start or pass arguments to MD. This means that MD to SE communication is a one way transaction.
. . However, MD does have the ability to monitor for changes in the game and some of those changes can be manipulated by SE. MD Control(MDC) has been created to allow you to use SE to manipulate: start, stop, and send variables, your MDs by simply passing a key and any variables to MDC.
. . MDC accomplishes this by creating a logic circuit consisting of control ships and stations in an isolated sector. The SE then utilizes the logic circuit to communicate with the MD. Game performance should not be affected, since there is very little processing required and the ships/stations race logic is turned off.


Downloads

Installation

Everyone:
  • Change the directory name from "director Vanilla" or "director XTC" to "director" based on which map you are using Vanilla or XTC.
  • Reinit script cache, then follow the instruction messages.
    [ external image ]v1.13a (zip)
    Contents:
    MD_Control_Sector.xml -- (MD: Control sector/ships/stations creator)
    MD_variable.xml -- (MD: MDC's Variable handler)
    setup.md.control.xml -- (SE: MDC Setup)
    md.control.create.xml -- (SE: Initial setup of stations/ships)
    md.control.key.xml -- (SE: processes your key and sends it to main)
    md.control.main.xml -- (SE: activates MD)
    md.control.reset.xml -- (SE: resets ships and stations)
    9876-L044.xml -- (T: Contains control sector's name: MD Control)



    Developers:
    Note: The sector MD Control only appears on flat maps. If you are using the vanilla map style, then press 'm' until it is displayed in the description box, typically two times.

    [ external image ]dev1.11a (7z)
    Contents:
    MD_template.xml -- (MD: Template to follow to use MDC)
    MD_Example_Test.xml -- (MD: Example/Test MD)
    md.control.example.test.xml -- (SE: Used to activate MD_Example_Test



    • Example v1.1 - Testing Procedure
    1. Place all files in respective folders (MD in /director, SE in /scripts, T in /t)
    2. Load a save or create a new game
    3. Wait for pause and two messages:
      1. MDC-SE: script delay
      2. MDC-MD: control sector creation
    4. Reinit script cache
    5. Wait for pause and message, MDC-SE: Ready
    6. Open script editor
    7. Run: -md.control.example.test-
Last edited by h2o.Ava on Fri, 21. Jan 11, 01:30, edited 29 times in total.

h2o.Ava
Posts: 317
Joined: Sun, 12. Oct 08, 04:04
x3tc

Post by h2o.Ava » Mon, 15. Nov 10, 02:30

What does MDC allow you to do?

MDs conditionals are not flexible.
SE is extremely flexible.
Using SE you can determine exactly when and why a MD is run.
Use a script to change backgrounds, add suns, give rewards, start missions.
(If you have more ideas on how this can work. Please post them.)



How MDC works

---Activation---
-Script Engine-
After assigning each of your MDs a unique 6 digit key. Have your script send that key to MD Control, which will activate the MD assigned to that key.

Code: Select all

Example:
If your MD is assigned the key 123456, then when you want your script to activate that MD, you send the key 123456 to MD Control.

$key = 123456
= [THIS]->call script 'md.control.key' : key=$key

-Mission Director-
The first condition for each MD needs to use the following format:

Code: Select all

(key = 987654)
    <cue name="MDControl_987654">
      <condition>
        <check_all>
          <object_is_docked object="MDControl.ControlShip0" dockobject="MDControl.ControlStation9"/>
          <object_is_docked object="MDControl.ControlShip1" dockobject="MDControl.ControlStation8"/>
          <object_is_docked object="MDControl.ControlShip2" dockobject="MDControl.ControlStation7"/>
          <object_is_docked object="MDControl.ControlShip3" dockobject="MDControl.ControlStation6"/>
          <object_is_docked object="MDControl.ControlShip4" dockobject="MDControl.ControlStation5"/>
          <object_is_docked object="MDControl.ControlShip5" dockobject="MDControl.ControlStation4"/>
        </check_all>
      </condition>

(key = 999000)
    <cue name="MDControl_999000">
      <condition>
        <check_all>
          <object_is_docked object="MDControl.ControlShip0" dockobject="MDControl.ControlStation9"/>
          <object_is_docked object="MDControl.ControlShip1" dockobject="MDControl.ControlStation9"/>
          <object_is_docked object="MDControl.ControlShip2" dockobject="MDControl.ControlStation9"/>
          <object_is_docked object="MDControl.ControlShip3" dockobject="MDControl.ControlStation0"/>
          <object_is_docked object="MDControl.ControlShip4" dockobject="MDControl.ControlStation0"/>
          <object_is_docked object="MDControl.ControlShip5" dockobject="MDControl.ControlStation0"/>
        </check_all>
      </condition>

---Passing Variables---
Numbers from 0 to 25000 can be passed from SE to MD.
SE: Vars[0] becomes MD: MDC_variable.0
SE: Vars[9] becomes MD: MDC_variable.9


---FYI and other ramblings---
- Currently 900,000 unique MDs are supported (100000 to 999999)
- MD Control will allow only one script to use it at a time and needs to reset itself after each use. Your script will be queued and the MDs will run first come first serve.
- Passing variables from SE to MD should be done through a secondary MD and not directly sent into the scripter's core MD. The secondary MD receives the variable from its respective ship's/station's name, chosen by the scripter, and assigns it to cuename.variable which can then be read by other MDs when needed.
Last edited by h2o.Ava on Sat, 11. Dec 10, 03:33, edited 9 times in total.

h2o.Ava
Posts: 317
Joined: Sun, 12. Oct 08, 04:04
x3tc

Post by h2o.Ava » Mon, 15. Nov 10, 02:31

Todo for MD Control - 1.2
(25% done)

Script:
10% - Pass complex variables to MD
-- 25% - Strings
-- 25% - Complex Variables
-- 25% - Negative Numbers
(doesn't seem like we can pass anything but strings and numbers)
(An object library might need to be created in MD so SE can pass MD a number and MD will translate it into classes and types)


MD:
10% - Receive strings from SE and convert them to numbers/classes/types



-----------------------------
Tutorial/Instructions:
50% - Standardization
50% - Example
Last edited by h2o.Ava on Sat, 11. Dec 10, 03:30, edited 17 times in total.

User avatar
apricotslice
Posts: 14129
Joined: Sun, 16. May 04, 13:01
x4

Post by apricotslice » Mon, 15. Nov 10, 07:27

What your doing is less important here than how your doing it.

So please explain the object of the exercise, and then how each part of it interacts with each other.

The object as I see it here, is to explain to us step by step, how to get MD and script to interact. So the what is just a means to an end to explain the how.

So far you have simply demonstrated that creating in MD can be used by a script. Its the interaction and the mechanism for doing so, back and forth, that needs detailed explaining.

Its encouraging to see you get this far, but so far, I'm not really sure how, or if the method is reproducable for varying situations.

User avatar
enenra
Posts: 7150
Joined: Fri, 8. Apr 05, 19:09
x4

Post by enenra » Mon, 15. Nov 10, 08:41

I'm not exactly sure what you're trying to do, h2o.AvA. :s

MD and scripts can communicate, it just isn't as easy as forwarding a variable for the SE to MD side. But MD and SE can work together and they have been used in conjunction before - see for example the New Home Plot (the Sudoku Part).

h2o.Ava
Posts: 317
Joined: Sun, 12. Oct 08, 04:04
x3tc

Post by h2o.Ava » Mon, 15. Nov 10, 09:05

Do you mean that I can already start a MD from a script?
What is the name of New Home's director file?

edit: CSV, I'll read those and see.

User avatar
enenra
Posts: 7150
Joined: Fri, 8. Apr 05, 19:09
x4

Post by enenra » Mon, 15. Nov 10, 09:13

h2o.AvA wrote:Do you mean that I can already start a MD from a script?
What is the name of New Home's director file?

edit: CSV, I'll read those and see.
It's not directly possible to start MD code from a script. But as both can read and change existing objects, it's relatively easy to pass information to the MD which has been done in the New Home Plot.

User avatar
apricotslice
Posts: 14129
Joined: Sun, 16. May 04, 13:01
x4

Post by apricotslice » Mon, 15. Nov 10, 09:14

Actually enenra, what we really need is the ability to start an MD from a script and the ability for an MD to call a script.

There are things which both do better than the other and it would be good to be able to start or stop the other from the other, and run each other from the other.

For example, missions that trigger from the variables in a script. You only want the mission to trigger becoming available when the script has determined it should.

Likewise, during a mission, an MD could call a specific script to allow for specific ship movements to happen. The MD can create the ships, but a script can make them do things.

The situation with game starts where too big a start file conflicts with too many setup scripts. We get around it by setting a gloabl variable so that the setup scripts get run only on the second game load, but it would be very useful for modding for that same script to also call an MD to delay the start or to remove a complicate start into its own MD file, so keeping start.xml simple. The code for my AMS start almost doubles the size of start.xml for example, and it would be useful if that code could be executed out of a script after the second game load when the rest of the mod is set up.

Edit :
I see direct interaction between script and MD as a major oversight in the creation of the MD.

User avatar
enenra
Posts: 7150
Joined: Fri, 8. Apr 05, 19:09
x4

Post by enenra » Mon, 15. Nov 10, 09:25

There is a command to run a script in the MD.

Code: Select all

          <run_script>
            <scriptargs>
              <scriptvalue datatype="ship" datavalue="{player.ship}">
                <scriptarray>
                  <scriptvalue datatype="string" datavalue="yadda"/>
                  <scriptvalue datatype="string" datavalue="yadda2"/>
                </scriptarray>
              </scriptvalue>
            </scriptargs>
          </run_script>
As for the SE to MD side, see the New Home Plot.

User avatar
apricotslice
Posts: 14129
Joined: Sun, 16. May 04, 13:01
x4

Post by apricotslice » Mon, 15. Nov 10, 09:30

When is the MD going to get some decent documentation ?

Seems like it has many things no one knows anything about.

And besides, that example made no sense whatsoever.

Not being critical, but it just makes no sense to someone who only has a basic understanding of MD.

Theres a lot the MD does that makes no sense to me at all.

And even though I can read the code, without a decent manual for using the MD, I cant write it.

h2o.Ava
Posts: 317
Joined: Sun, 12. Oct 08, 04:04
x3tc

Post by h2o.Ava » Mon, 15. Nov 10, 09:34

Code: Select all

<run_script script="csv.hacking.init">
     <scriptargs>
          <scriptvalue datatype="string" datavalue="init"/>
          <scriptvalue datatype="object" datavalue="{object@CSV_toplevel.CafeCPU}"/>
     </scriptargs>
</run_script>

<condition>
     <object_exists object="{actor@CSV_Chapter6_vorFirewall.actor123}" negate="1"/>
</condition>
This runs the script csv.hacking.init and passes the arguments str.mode and obj.cafe into the script. MD passes "string" and "object" so the script needs an argument starting with "str." and "obj." each of their respective Var/Types.
The MD then monitors for the destruction of the passenger "actor123", the script will destroy the passenger at some point.


I'm trying to create a process where we can start MDs directly with scripts.
Passing variables will come later, but I think it is doable.
The variables would need to be simple, but we could do more than just [TRUE] and [FALSE]. With one more ship we could do 10 variable outcomes per MD. The scriptor could write multiple MDs so he's not limited to just 10.
Such as, a scriptor could write an MD with all the variables he wants to pass to his core MD, then he'd send MDC the combination to activate his variable MD with a variableShip (would need to be created inaddition to controlShips) the variable MD would then "pass" the variable to the scriptors core MD, via the core MD monitoring for that variable.

edit: improved analysis of passing args to script and added how New Home receives information back from the script

User avatar
Ketraar
EGOSOFT
EGOSOFT
Posts: 11741
Joined: Fri, 21. May 04, 17:15
x4

Post by Ketraar » Mon, 15. Nov 10, 11:31

apricotslice wrote:When is the MD going to get some decent documentation ?
You mean besides the existing info? My guess is the day you start will be the first one. :-P

Anyway, there is rarely any need to have info from SE to MD. Also starting scripts from MD is something I'd avoid if possible.
Having said that, its not rocket science, have a TL with empty cargo far away or in a non existing sector, monitor it for e-cell count in MD. Add e-cell with SE to trigger MD, simple, just need to think of it, sure there are tons of other ways.

MFG

Ketraar
Image

h2o.Ava
Posts: 317
Joined: Sun, 12. Oct 08, 04:04
x3tc

Post by h2o.Ava » Mon, 15. Nov 10, 11:43

Now that's a good idea.
Use the ships stats and cargo to pass information.
Can MD pull exact data off an object and store it in a variable?
Like if it has 512 ecells, its hull is at 1000035, anything else that might be able to pass information?

User avatar
Ketraar
EGOSOFT
EGOSOFT
Posts: 11741
Joined: Fri, 21. May 04, 17:15
x4

Post by Ketraar » Mon, 15. Nov 10, 11:45

Pretty much anything, yes.

Look at the {object.* variables in the MD html (pretty much at the bottom) you should find lots that read info from objects, being it internal (cargo) or external values.

MFG

Ketraar
Image

User avatar
enenra
Posts: 7150
Joined: Fri, 8. Apr 05, 19:09
x4

Post by enenra » Mon, 15. Nov 10, 12:35

@aprictoslice

Currently, the only way to effectively learn MD coding is to study the existing files extensively and then writing your own code, starting with, for example, a simple mission, later a first generic mission, then a next one etc.
During learning you'll need someone who knows the MD well to work with you, answer your questions quickly and look through your code.

That's the way I've learned it - only took me around 4 months of working with the MD every day around 6 hours. :P

There is an existing documentation pdf, which is horribly outdated but still useful to understand the general structure. There's also the html file Ketraar mentioned which I recommend strongly. No better place to learn of the MD's cspabilities. Finally you might want to take a look at the first mission I wrote and documented extensively - the Rescue the Boron Princess-mission. :)

h2o.Ava
Posts: 317
Joined: Sun, 12. Oct 08, 04:04
x3tc

Post by h2o.Ava » Mon, 15. Nov 10, 12:38

MD:
value={object.name@&lt;object&gt;}
example={object.name@enemy}

SE:
<RefObj> -> set name to <Var/String>

Found the best one.
This is becoming easier, I can stay at 10 total ships, and change the names of the stations and ships allowing for 20 variables to be passed between MD and SE.
Time for a break.. just browsed through 16k lines of director.xsd..

User avatar
apricotslice
Posts: 14129
Joined: Sun, 16. May 04, 13:01
x4

Post by apricotslice » Mon, 15. Nov 10, 12:53

enenra wrote:@aprictoslice
Currently, the only way to effectively learn MD coding is to study the existing files extensively and then writing your own code, starting with, for example, a simple mission, later a first generic mission, then a next one etc.
During learning you'll need someone who knows the MD well to work with you, answer your questions quickly and look through your code.

That's the way I've learned it - only took me around 4 months of working with the MD every day around 6 hours. :P

There is an existing documentation pdf, which is horribly outdated but still useful to understand the general structure. There's also the html file Ketraar mentioned which I recommend strongly. No better place to learn of the MD's cspabilities. Finally you might want to take a look at the first mission I wrote and documented extensively - the Rescue the Boron Princess-mission. :)
There was a time when I would have taken you up on that little challenge. But I dont have the brain for it anymore.

My programming days are over. Learning a new language is beyond me now. Neither the brain power or the motivation is there any more.

Now theres a hell of an admission. Getting old sux. :(

The most I can do these days is cut and paste the more simple bits.

Doesnt stop me asking for the impossible to make it easier for other people though. :D

h2o.Ava
Posts: 317
Joined: Sun, 12. Oct 08, 04:04
x3tc

Post by h2o.Ava » Tue, 16. Nov 10, 23:00

I'm looking for someone that is good at manipulating strings.
If you're interested in assisting, I'd love it if you could take this string and turn it into 10 variables.

(00,11,22,33,44,55,66,77,88,99)

var1 = 00
var2 = 11
etc..etc


Also, if someone has a more user friendly idea for the combination, I'd love to hear it.

User avatar
apricotslice
Posts: 14129
Joined: Sun, 16. May 04, 13:01
x4

Post by apricotslice » Tue, 16. Nov 10, 23:41

Just insert it into an array and address each element of the array.

Not sure how you would do it in SE, but in other languages, you just describe the array as 10 elements long, then describe it as a string the same length. Copy string to array-string and then access via array elements.

No idea how to do that in SE though.

h2o.Ava
Posts: 317
Joined: Sun, 12. Oct 08, 04:04
x3tc

Post by h2o.Ava » Wed, 17. Nov 10, 00:28

Passing it via an array would be the easiest thing to do.
Although, I'd prefer that the scripter only has to type the key in one line, exactly like the $pageid=9876, instead of creating an array.

Looking at it now, it seems 10 stations is more than what would ever be needed.
Dropping it down to 6ships and 10stations: cships(0-5), the position of number, and 10cstations(0-9), the number in the position. Making the key 6 digits long and capable of using duplicate numbers (999999), totaling 1,000,000 unique MDs. Eventually I'll create a list of only the keys in use.

Question:
anyone know how MD handles strings and numbers?
if a string is all numbers, is it viewed as a string or number?
can it convert strings to numbers?

Thank you everyone for all the assistance you have thus far provided.

Post Reply

Return to “X³: Terran Conflict / Albion Prelude - Scripts and Modding”