I_talk_in_pictures
Registered:1601944338 Posts: 37
Posted 1601946386
Reply with quote
#1
I added a new video as a tutorial for using Artemis Macro Language. I also signed up here to field any topics that may be generated from it.https://youtu.be/UvjvdRsSJ40
Mike Substelny
Administrator
Registered:1375273622 Posts: 2,990
Posted 1601988924
Reply with quote
#2
Thanks! This will make it a lot easier to learn!
__________________"The Admiralty had demanded six ships; the economists offered four; and we finally compromised on eight." - Winston Churchill
mattssheep4
Registered:1460345605 Posts: 128
Posted 1602078584
Reply with quote
#3
Hey, it's astrolamb-gaming from github. Would you like to use this thread as a place for discussion/bug reports?
__________________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
Registered:1460345605 Posts: 128
Posted 1602085890
Reply with quote
#4
A helpful reference for utilizing macro expressions. This link takes you to the one which shows examples of using conditionals to determine what value should be used in a script.https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Nesting_templates
__________________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
Registered:1460345605 Posts: 128
Posted 1602094272
· Edited
Reply with quote
#5
Another feature request:
When iterating over a range, it would be great if there was some way to only add a section to the mission script if a condition is met. For example,
<range name="options"> <value name="one" value="1"/> <value name="two" value="2"/>
</range>
<repeat _length="4"> <repeat range="options" _as="opt"> <if condition="${_index==opt}"> // Do things here if true </if> </repeat> </repeat>
Maybe put the condition as part of the expand tag?
<expand _if="${_index==opt}"> // do things </expand>
Edit:
The skip attribute for imports kind of does this, but imports have to be a child of the mission_data, which isn't ideal for my purposes. I'd like it to be a bit more dynamic. Also having an else sort of thing could be useful...
__________________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:1601944338 Posts: 37
Posted 1602104838
Reply with quote
#6
The ability to skip or conditionally include code already exists. <repeat> and <expand> support a _skip attribute (like your _if suggestion, but the inverse logically) I thought it was more common to think about NOT including stuff. Also I think marking things a skip would be more straight forward than a 'if/else' type of setup. _skip with repeat
<repeat _range ="Anomalies" _skip ="${object == 'A5'}" >
<event name ="${anomaly} Destroyed" >
<if_not_exists name ="${object}" />
<if_variable name ="${anomaly}" comparator ="EQUALS" value ="1.0" />
<set_timer name ="${anomaly}" seconds ="Respawn_Anomaly_Time" />
<set_variable name ="${anomaly}" value ="2.0" />
</event >
<event name ="${anomaly} Respawn" >
<if_variable name ="${anomaly}" comparator ="EQUALS" value ="2.0" />
<if_timer_finished name ="${anomaly}" />
<create type ="Anomaly" pickupType ="${pickupType}" x ="95000.0" y ="${y}" z ="95000.0" name ="${object}" />
<set_relative_position name2 ="${object}" distance ="39000" angle ="${angle}" name1 ="." />
<set_variable name ="${anomaly}" value ="1.0" />
</event >
</repeat >
</mission_data >
This example
<mission_data version="1.0">
<templates >
<template name ="hello" >
<big_message title ="${message}" />
</template >
</templates >
<start >
<expand _template ="hello" message ="Hello, World" />
<expand >
<big_message title ="No skip" />
</expand >
<expand _skip ="True" >
<big_message title ="Should skip" />
</expand >
<expand _skip ="false" >
<big_message title ="False skip" />
</expand >
<expand _skip ="${0==1}" >
<big_message title ="False macro skip" />
</expand >
<expand _skip ="${1==1}" >
<big_message title ="True macro skip" />
</expand >
</start >
</mission_data >
GENERATES
<mission_data version ="1.0" >
<start >
<big_message title ="Hello, World" />
<big_message title ="No skip" />
<big_message title ="False skip" />
<big_message title ="False macro skip" />
</start >
</mission_data >
I_talk_in_pictures
Registered:1601944338 Posts: 37
Posted 1602105780
Reply with quote
#7
Also, Yes internally the system uses Javascript Template literals. But as you found and others may run into. Most values in the system as Strings so adding two value together is likely concatenating string. You can specify that a value should be treated as an integer, or float using included helper functions. There are functions to convert to the strings to number _.int() _.float() For example: ${_.int(y) * _.int(x_across) + _.int(x) + 1} there is also _.map() to convert<value x="${_.map.x(2.3)}" y="0.0" z="${_.map.z('B.25')}" navpoint="NAV_01" /> So x is about 1/3 in on grid 2 and a quarter way down in the B line. This next part is a bit more advanced. You can add new function for use in template string as well, by importing javascript code.This XML <mission_data version="1.0"> <templates> <template name="test"> <big-message title="${plugins.MyPlugin.message}"/> </template> </templates> <mission_description> Multiplayer mission with Jump drive ships. Capture the most eggs by towing them to your station. Eggs can only be towed at impulse. Comms Button at start of mission must be pressed to join game. </mission_description> <imports> <import name="script-simple-fragment.js" /> </imports> <start> <expand _template="test"/> <expand> <big-message title="inline ${plugins.MyPlugin.message}"/> </expand> </start> </mission_data> Importing this Javascript "script-simple-fragment.js" class MyPlugin{ get text() { return "Hello, classes" } } async function init( basedir) { //console.log('Plugin init') } exports.init = init exports.MyPlugin = { message: "Hello, Javascript", myPlugin: new MyPlugin() }Generates <mission_data version="1.0"> <mission_description> Multiplayer mission with Jump drive ships. Capture the most eggs by towing them to your station. Eggs can only be towed at impulse. Comms Button at start of mission must be pressed to join game. </mission_description> <start> <big-message title="Hello, Javascript"/> <big-message title="inline Hello, Javascript"/> </start> </mission_data> They init function is asynchronous. So you could get data from a web page, database etc. when the plugin is loaded.
mattssheep4
Registered:1460345605 Posts: 128
Posted 1602110253
· Edited
Reply with quote
#8
Ok, that's awesome that you can call JS code! I played around with that for a bit, using <script> tags, but without success. Great that repeat and expand use skip, too!
Edit:
Is there a way to pass variables to a js function? I.e.
<big-message title = "inline ${plugins.MyPlugin.convert(_index)}" />
exports.MyPlugin = { result: convert(value) } Edit2:
Been doing a lot of testing.
I haven't found a way to pass a variable to a js function, but I found something of a workaround (in the case of roman numerals) in returning an array and accessing the appropriate index. However, it seems that plugins can only be used in the main _SOURCE file, not in any imported files.
__________________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:1601944338 Posts: 37
Posted 1602114992
Reply with quote
#9
Yes, of course you can pass any value to a javascript function as an argument. I originally wrote a plug in to read and parse the Mission Log files. I later built it in to import. This should be a pretty powerful system. To write missions that use any form of persistence. Or if you wanted to regenerate the mission with different values. See this examplehttps://github.com/dougreichard/artemis_macro_language/tree/master/examples/presistance It shows how to use JSON from the log file. and to run AML so it regenerates the script whenever the log changes. The source of data doesn't need to be the log file. You can use plugins to get it from wherever you need to. Write an init() function in the plugin. Then write functions to access the data through template strings. Anything you can do in NodeJS you can do in AML through the plugins. - Get data from anywhere via plugins - generate the mission - watch for the log file to change via AML -l or some other program - capture the log data - Rinse/Repeat
I_talk_in_pictures
Registered:1601944338 Posts: 37
Posted 1602115331
Reply with quote
#10
I think you may need to import plugins in the file where it is used. Each files data is separate as it is read, and then later only values merged.
I_talk_in_pictures
Registered:1601944338 Posts: 37
Posted 1602115874
· Edited
Reply with quote
#11
Also, your example is incorrect.<big-message title = "inline ${plugins.MyPlugin.convert(_index)}" /> exports.MyPlugin = { result: convert(value) }Should probably be: <big-message title = "inline ${plugins.MyPlugin.convert(_index)}" /> function convert(..) { } exports.MyPlugin = { convert: convert }
mattssheep4
Registered:1460345605 Posts: 128
Posted 1602116224
· Edited
Reply with quote
#12
Sorry, my example poorly described my problem. I want to do something like this, within the xml files:
<big-message title="${plugins.RomanNumerals.romans(4)}"/> As for importing, I've tested importing the .js file in other files, too, without success.
<imports> <import name="utilityFunction.js"/> </imports>
<expand> <big-message title="${plugins.RomanNumerals.romans[4]}"/> </expand>
The above works when located in the _SOURCE.xml file, but not when located in any files that are imported into _SOURCE. returns an array, so accessing the array works, but I'd rather be able to pass a parameter to the function from the xml. EDIT:
Never mind, I see what you're saying. Thank you!
I can confirm that it's still not working in other files though, with or without the import.
__________________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:1601944338 Posts: 37
mattssheep4
Registered:1460345605 Posts: 128
Posted 1602458155
Reply with quote
#14
Any chance there could be way to merge events that have the same name into a single event?
__________________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:1601944338 Posts: 37
Posted 1602467972
Reply with quote
#15
It is possible, but FAR more complex than the merging start that is done. Start is all commands and merging is straight-forward. Events have conditions and order matters for that. As well as just need to recognize what is a condition vs a command. I'm not sure I see a use that is compelling enough for that. Do you have a specific example to show the benefit? Perhaps there is a different solution exist or can be added for what you're trying to do.