adding and deleting time scales

5.69K viewsScripting
0

Same issue different model.

Thgis creates a non destructive method of adding to a time scale where entries may have taken place. The adding of time works but deleting does not. Any ideas what I am doing wrong.

Also documentation would be helpful.

script below and file attached.
——————————————————————-
void perform()
{
def currentConstruction = (int) |Matrix1::Construction|.children.size()
def currentPerformance = (int) |Matrix1::Performance|.children.size()

def desiredConstruction = (int) |Matrix2::Construction|.value;
def desiredPerformance = (int) |Matrix2::Performance|.value;

if(desiredConstruction > currentConstruction)
{
|Matrix1::Construction|.children.createAt(0,(-desiredConstruction)..<(-currentConstruction)).each {name = “”Month “” + name ;}
}
else if(desiredConstruction < currentConstruction)
{
|Matrix1::Construction|.children.get((-currentConstruction)..<(-desiredConstruction)).delete()
}

if(desiredPerformance > currentPerformance)
{
|Matrix1::Performance|.children.create((currentPerformance+1)..desiredPerformance).each {name = “”Month “” + name ;}
}
else if(desiredPerformance < currentPerformance)
{
|Matrix1::Performance|.children.get((desiredPerformance+1)..currentPerformance).delete()
}
}

boolean enabled()
{
return !(|Matrix1::Construction|.children.size() == |Matrix2::Construction|.value
&& |Matrix1::Performance|.children.size() == |Matrix2::Performance|.value);
}

Attachments

script.model
0

milo5255,

I have played with your model and your code and found this solution:

[code:1nzvr17x]
void perform()
{
def currentConstruction = (int) |Matrix1::Construction|.children.size()
def currentPerformance = (int) |Matrix1::Performance|.children.size()

def desiredConstruction = (int) |Matrix2::Construction|.value
def desiredPerformance = (int) |Matrix2::Performance|.value

def int i

if(desiredConstruction > currentConstruction)
{
|Matrix1::Construction|.children.createAt(0,(-desiredConstruction)..<(-currentConstruction)).each {name = “”Month “” + name ;}
}
else if(desiredConstruction < currentConstruction)
{
// |Matrix1::Construction|.children.get((-currentConstruction)..<(-desiredConstruction)).delete()
for (i = currentConstruction – 1; i >= desiredConstruction; i–)
{
|Matrix1::Construction|.children.get(0).delete()
}
}

if(desiredPerformance > currentPerformance)
{
|Matrix1::Performance|.children.create((currentPerformance+1)..desiredPerformance).each {name = “”Month “” + name ;}
}
else if(desiredPerformance < currentPerformance)
{
// |Matrix1::Performance|.children.get((desiredPerfor mance+1)..currentPerformance).delete()
for (i = currentPerformance – 1; i >= desiredPerformance ; i–)
{
|Matrix1::Performance|.children.get(i).delete()
}
}
}

boolean enabled()
{
return !(|Matrix1::Construction|.children.size() == |Matrix2::Construction|.value
&& |Matrix1::Performance|.children.size() == |Matrix2::Performance|.value)
}
[/code:1nzvr17x]

These lines were not working:
[code:1nzvr17x]
|Matrix1::Construction|.children.get((-currentConstruction)..<(-desiredConstruction)).delete()
[/code:1nzvr17x]

and

[code:1nzvr17x]
|Matrix1::Performance|.children.get((desiredPerfor mance+1)..currentPerformance).delete()
[/code:1nzvr17x]

because the get() function accepts interger values only and can’t work with ranges.

My solution replaces these two lines with a corresponding for loop to iterate through the items:

[b:1nzvr17x]Construction[/b:1nzvr17x]
[code:1nzvr17x]
// |Matrix1::Construction|.children.get((-currentConstruction)..<(-desiredConstruction)).delete()
for (i = currentConstruction – 1; i >= desiredConstruction; i–)
{
alert(i)
|Matrix1::Construction|.children.get(0).delete()
}
[/code:1nzvr17x]

[b:1nzvr17x]Performance[/b:1nzvr17x]
[code:1nzvr17x]
// |Matrix1::Performance|.children.get((desiredPerfor mance+1)..currentPerformance).delete()
for (i = currentPerformance – 1; i >= desiredPerformance ; i–)
{
|Matrix1::Performance|.children.get(i).delete()
}
[/code:1nzvr17x]

Check the attached model file including the updated code.

Is this a possible solution to your problem?

Regards,
Dominik

You are viewing 1 out of 6 answers, click here to view all answers.