Page 1 of 1

AtomName

Posted: Friday 17 October, 2014 - 12:11
by pippo
Hello,

I want to label a specific product atom in a server atom. The product I want to label is located inside a package, so one package includes 20 products. My problem now is that I cannot access the product atoms in this package!

When I use for example

SetLabel([ProductEnergy],Label([ProductEnergy]) + 20, i)

the programme just labels the package and not the product itself. Is there any way to access the product by its atomname ("Product")?

When I use

SetLabel([ProductEnergy],Label([ProductEnergy]) + 20, [Product]) or just (..., Product)

it does not work or I will get an error message! I also searched in the index of the help file, but cannot find any solution for such atomname access. I don't think it's a big deal, but I cannot find any solution.

Would be great if somebody could help me!

Cheers

Pippo

Re: AtomName

Posted: Wednesday 22 October, 2014 - 18:13
by HarryBunnik
Hello,

It is possible to access an atom within another atom (i) by using first(i) or Rank(1, i). But on which product in the package in the server do you want to set this label? Only on the first of the 20?

Code: Select all

  Label([ProductEnergy], First(i)) := ...
Or on all?

Code: Select all

Repeat(
  Content(i), 
  Label([ProductEnergy], rank(count, i)) := ...
)
I wouldn't refer to atoms using their name (AtomByName([])), since this is a relatively slow and you will need unique names.

I hope this helps you a bit further,

Cheers,

Harry

Re: AtomName

Posted: Friday 24 October, 2014 - 12:20
by pippo
I want to label all 20 atoms in the package!

When I use (i) in the "Trigger on Exit" function of the server atom I only adress the package and not the content of the package. That is exactly my problem!

Re: AtomName

Posted: Monday 27 October, 2014 - 11:19
by HarryBunnik
Hello,

That is correct, i is the package.

And with the second snippet of code, you are looking within the package (i) for it's content "content(i)"and than execute the code for each occurrence "repeat" within that package (i) by referring to it using "rank(count, i)". So in your case it will find that the package (i) contains 20 products and will than execute the "Label([ProductEnergy], rank(count, i)) := ..." 20 times, once for each product within the package. The count is automatically increased from 1 to 20 within the repeat loop, so each product is individually set.

I hope this helps you further,

Cheers,

Harry

Re: AtomName

Posted: Monday 27 October, 2014 - 16:56
by pippo
Ok, I understand the issue now!

But I still have the problem that I don't know how this exactly looks like in my special case.

I forgot to say that other server in this system should do the same. So which each single server the label "ProductEnergy" should add the server-specific value of the energy consumption to the label. Therefore I need the addition from the existing value from the other server(s) before with the new value from the current server. So I tried to use "Label([EnergyProduct])+" the new value (20 watt-hour).

With your advice I thought of:

Repeat(
Content(i), SetLabel([EnergyProduct],Label([EnergyProduct])+20,rank(count, i))
)

But that is of cource not working at all!
I don't know exactly how to transfer your advice to the above problem.
Sorry, but I am not an expert :|

Cheers

Re: AtomName

Posted: Monday 27 October, 2014 - 17:21
by HarryBunnik
I'm not entirely sure what you mean, but when I look at your code, I think you're quite close.

Would the following code do the trick?

Code: Select all

Repeat(
  Content(i), 
  SetLabel([EnergyProduct],Label([EnergyProduct], rank(count, i))+20,rank(count, i))
)
I think that what you were missing is a reference within the original label "Label([EnergyProduct], rank(count, i))" that you want to increase with the 20 Wh.
What we do with this code is loop through your package and add for each label "EnergyProduct" on each product "rank(count, i)" the required 20 Wh and write that back to the same label "EnergyProduct".

If the package now passes through 2 servers where this code is defined on the Exit trigger, both will add 20 Wh to all the products within the package, thereby in total increasing it with 40Wh per product.

Is this what you require?

Cheers,

Harry

Re: AtomName

Posted: Monday 03 November, 2014 - 17:14
by pippo
Yeah, that works entirely perfect with some further modifications :)

That was the help I was searching for!

Thanks a lot Harry!