Sign up Calendar Latest Topics
 
 
 


Reply
  Author   Comment   Page 2 of 3      Prev   1   2   3   Next
mattssheep4

Avatar / Picture

Registered:
Posts: 128
Reply with quote  #16 
It's not particularly necessary, I know how to go about doing what i have in mind other ways. For the TSN Sandbox I'm working on separating all of our various systems into separate files, and it would be convenient to put stuff that's specific to a particular system but organizationally (scripting-wise) would be better placed elsewhere into the system file. But as I say, if it's not a particularly simple task then I'll go with existing methods.
__________________

Captain Matthew Vaj

Former Commanding Officer, TSN Viper, 2nd Space Fleet, 4th Light Division

TSN RP Community - Listen to our Fleet News Service! - Join our Discord Server!

Intelligence Officer of the Cygnus Campaign

mattssheep4

Avatar / Picture

Registered:
Posts: 128
Reply with quote  #17 

Could you give an example of this:

Quote:
They init function is asynchronous. So you could get data from a web page, database etc. when the plugin is loaded.


Particularly webpage data? Would you just use normal JS functionality? Could jQuery for example be used with it?


__________________

Captain Matthew Vaj

Former Commanding Officer, TSN Viper, 2nd Space Fleet, 4th Light Division

TSN RP Community - Listen to our Fleet News Service! - Join our Discord Server!

Intelligence Officer of the Cygnus Campaign

I_talk_in_pictures

Registered:
Posts: 37
Reply with quote  #18 
NOTE: The video example linked below is older and there a better way now to used the Artemis Log data by using the ability to import the log data via an import and not need to write javascript, however it is a good example of a plugin getting data via init.

Here is a video I made to demo persistence and plugin.

https://youtu.be/jsVbwP0rRwU

It shows using init and in this case loading a file. The example could be use as an example to do anything like getting data from a web server, database server etc. Or by reading the log data in this way you might decide to update a file or database.

Be aware of these things:
1) This is Sever side javascript via node JS (which AML.EXE is really node)
2 if you haven't used node, you may want to try some standalone things before doing a plugin
3) It is not the browser so using JQuery probably isn't the best approach 
4) You can find additional libraries for node, but likely need to install node JS and use its NPM tool to install them
5) To get data from a web server you could check out this article and I'd suggest using the node-fetch version of the example
https://www.valentinog.com/blog/http-js/

The short answer  is:
1) Install node js
2) in the folder where your plugin is install node-fetch (npm -i node-fetch)
3) Write you init using node-fetch 



const fetch = require("node-fetch");
const url = "https://jsonplaceholder.typicode.com/posts/1";
async function init(basedir) {
  try {
    const response = await fetch(url);
    const json = await response.json();
    console.log(json);
  } catch (error) {
    console.log(error);
  }
};
exports.init = init






dragonfly

Registered:
Posts: 117
Reply with quote  #19 
Confusing but it's definitely just me. I'll watch the video again and hopefully I'll get it right. Thanks!
I_talk_in_pictures

Registered:
Posts: 37
Reply with quote  #20 
That video was meant to just show that possibility, was never meant to be a tutorial. 

There is a lot of flexibility to things. It is hard to capture it all, but there are some examples.

If you are more comfortable with another programming language you could use it to write XML or JSON prior to calling AML.

You can then import that XML or JSON data.

You can also see the EXAMPLES
https://github.com/dougreichard/artemis_macro_language/tree/master/examples

The ones starting with personalize are a number of different ways you might leverage as well.
- Passing data via the command line with --define
- passing data in the aml.json
- passing data via import of JSON
- pass data as xml via import with as='data'



mattssheep4

Avatar / Picture

Registered:
Posts: 128
Reply with quote  #21 
Currently a range cannot be used as a parameter in a template. Any chance that can/will be changed?

E.g.

<template name="Test_Ranges">
  <params>
    <param name="Range"/>
  </params>

  <repeat _range="Range" _as="test">
    <big-message text="${test.system} testing.....${test.height}."/>
  </repeat>

</template>


__________________

Captain Matthew Vaj

Former Commanding Officer, TSN Viper, 2nd Space Fleet, 4th Light Division

TSN RP Community - Listen to our Fleet News Service! - Join our Discord Server!

Intelligence Officer of the Cygnus Campaign

I_talk_in_pictures

Registered:
Posts: 37
Reply with quote  #22 
0.9 should let you do this, but not exactly as you suggested.

You pass the name of the range. But should cover what you want.




 <templates>
    <template name="test">
        <repeat _range="${r} _as="sh"">
          <set_variable name="${sh.ship}" value="1.0"/>
        </repeat>
    </template>
  </templates>



 <expand _template="test" r="Ships" />

This should work as well if the name is something you want to vary


 <expand _template="test" r="${myrange}" />
 
mattssheep4

Avatar / Picture

Registered:
Posts: 128
Reply with quote  #23 
So it seems that with 0.9, the `params` part of templates are no longer applicable/needed? They no longer need to be defined in the template?

Thanks so much btw, AML is quite spectacularly useful at this point.

__________________

Captain Matthew Vaj

Former Commanding Officer, TSN Viper, 2nd Space Fleet, 4th Light Division

TSN RP Community - Listen to our Fleet News Service! - Join our Discord Server!

Intelligence Officer of the Cygnus Campaign

I_talk_in_pictures

Registered:
Posts: 37
Reply with quote  #24 
The params tag has always been optional, but recommended.

They allow you the have a description, defaults and if they are optional.

When you include them you get more descriptive error messages as well.
i.e. it checks to see the values passed include what parameters are expected.

Without params, you would get a less descriptive generic error when the template string execution fails.

I also hoped for tools like the mission editor they could use params to help know what to present in a UI.

I look forward to seeing what people create with AML. Happy to know it has been useful.

I_talk_in_pictures

Registered:
Posts: 37
Reply with quote  #25 
As we discussed - there is more power there than we'd have time to document. I can point to some example with the rest 'up to the reader'.

Some of my favorite uses of templates are in the cruiser tournament. The "spawn" system is highly flexible specific to that mission. Spawn friendlies, enemies and track their tonage points.


https://github.com/dougreichard/artemis_macro_language/blob/master/test/modular/cruiser_tournament/Cruiser_Tournament_spawn.xml

https://github.com/dougreichard/artemis_macro_language/blob/master/test/modular/cruiser_tournament/Cruiser_Tournament_templates.xml


This has templates in templates (see the extra param) and some that let you set the abilities of with a list of abilities using string matching, it also uses a lookup table to find the proper tonage.

This example removed so much copy/pasted code that could easily have typo errors to small (IMHO) clearer way of creating things.


This lets you set abilities of an enemy in a nice way:

From a list of enemies like this

    <value name="B71" x="5000" y="0" z="41000" angle="200" race="Skaraan" hull="Executor" size="large"
                        extra="set:abilities" ability_captain="AniTorp" ability_clear="Teleport,shlddrain,LowVis,Stealth" />



You generate them with a simple repeat.


  <repeat _range="enemies">
                <spawn:create />
  </repeat>


If you look at the bonus fleet code the original was daunting. and mike said "never really worked". Well I think it works now, and is easy to expand or change. The errors I found while translating it were small typos that were really hard to recognize as errors.


https://github.com/dougreichard/artemis_macro_language/blob/master/test/modular/cruiser_tournament/Cruiser_Tournament_BonusFleets.xml


The tonage lookup table is here:
https://github.com/dougreichard/artemis_macro_language/blob/master/test/modular/cruiser_tournament/Cruiser_Tournament_Points.xml


mattssheep4

Avatar / Picture

Registered:
Posts: 128
Reply with quote  #26 

So I've successfully gotten my script to pull data from the web. Now, would it be possible to use pass JSON pulled from the web to work the same way as pulling a json file to set values. I know I can do stuff like this:


<repeat _length="${json.data.length}">
   <!-- Stuff here using ${json.data[_index]}-->
</repeat>


But being able to directly say "Set values from this data set" would be nice


__________________

Captain Matthew Vaj

Former Commanding Officer, TSN Viper, 2nd Space Fleet, 4th Light Division

TSN RP Community - Listen to our Fleet News Service! - Join our Discord Server!

Intelligence Officer of the Cygnus Campaign

I_talk_in_pictures

Registered:
Posts: 37
Reply with quote  #27 
Your example isn't super clear, but I think I have managed to get what you might want. As well as getting things you may have been asking for.


1) When plugin init function returns values, they are added to the set of values.


async function init(basedir) {
    //console.log('Plugin init')
    return {
        pA: {
            pB: {
                pC: [10, 20, 30]
            }
        }
    }
}


These values are accessible as if they were defined in a values section.


<big-message title="function ${pA.pB.pC[1]}"/>
 



2) repeat _ range can now handle more complex expressions


<repeat _range="pA.pB.pC" >


This can include plugin functions.

<repeat _range="plugins.MyPlugin.ar_func()" >


3) repeat now has an _item for accessing non-object items (or object as well)


<repeat _range="plugins.MyPlugin.ar_func()" >
    <big-message title="function ${_item}"/>
</repeat>


Useful if the range is a set of numbers, or strings.


I_talk_in_pictures

Registered:
Posts: 37
Reply with quote  #28 
So, assuming these changes, and assuming your web request is in an init.

Return the values, and they will be accessible as other values are.

mattssheep4

Avatar / Picture

Registered:
Posts: 128
Reply with quote  #29 
Perfect, exactly what I wanted! I do hope you don't feel that I'm pestering you with feature requests...
__________________

Captain Matthew Vaj

Former Commanding Officer, TSN Viper, 2nd Space Fleet, 4th Light Division

TSN RP Community - Listen to our Fleet News Service! - Join our Discord Server!

Intelligence Officer of the Cygnus Campaign

I_talk_in_pictures

Registered:
Posts: 37
Reply with quote  #30 
Cool. Took a couple of attempts, but repeats and import are much better now. You went right to pushing the limits and AML is better for it. Some of the requests were just a line or two. The repeats was a bit bigger not too major.

If you're up to it:

* Spread the word
* Share what you know
* You've already did some documentation updates any more would be great
* Also, I had hoped if enough people use it maybe a common library of templates would grow out of it


It is cool just knowing someone 1) actually used this and 2) used the plugin system to get web data!

I'm not much of an Artemis scripter but I got the idea from watching Mike and Darrin on the online armada and thought I could make a tool to help make people more productive and focus more on making the story.

Something to do when stuck at home.


Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.