sarbian/ModuleManager

Doing math on vectors

Closed this issue · 2 comments

these are a couple of features that I think could be really useful:

1 - the ability of doing math on vectors

example:

key = 1,0,3,4  // original vector

@key[1] += 2 // adds 2 to the second element in the vector

key = 1,2,3,4  // final result

2- the ability of targetting a specific vector in a node that has multiple copies of it

example:

Curve  // Original Node
{
key = 1,2,3
key = 2,0,4
key = 3,4,5
}
@Curve
{
@key[1],1 += 3       // adds 3 to the second element, of the second "key"
}
Curve
{
key = 1,2,3
key = 2,3,4   // final result
key = 3,4,5
}

the syntax I used is just an example :)

PS:

I hope this will allow also for the modification of all "key" vectors by using " ,* " instead of a specific number

With the forum down, I can't give you a link to sarbian's explanatory post at this time, but it is possible to "call out" individual members of a symbol-separated list, do math on them individually, and then assemble them back together. My SMURFF does this, like so:

@MODULE[ModuleEngines*]:HAS[@PROPELLANT[SolidFuel]],*
{
    key0 = #$atmosphereCurve/key,0[1, ]$ //get the keys -- the second element of the first space-separated list called "key".
    key1 = #$atmosphereCurve/key,1[1, ]$
    @key0 += 40 //modify values -- add 40 seconds to bring Kickback close to Space Shuttle SRBs.
    @key1 += 40
    @atmosphereCurve
    {
        @key,0 = #$key,0[0, ]$ $../key0$ $key,0[2, ]$ $key,0[3, ]$
        @key,0 ^= : +$:: //Snip out any trailing spaces, since not all keys have four elements
        @key,1 = #$key,1[0, ]$ $../key1$ $key,1[2, ]$ $key,1[3, ]$
        @key,1 ^= : +$::
    }
}

(FYI, you can put code blocks in GitHub comments with triple-accents ``` before and after.)

hi Kaa

I already know about that possibility, but that would not allow to edit an unknown amount of keys.

I need this feature in order to rescale atmospheres of mods like RSS which have 71 keys in the same node :)

I've already asked Sarbian and he told me he would look into this, so I opened the issue to help with keeping track of this ;)

thanks anyways for your suggestion