|
Geggs Beginner
Joined: 13 Aug 2013 Posts: 14
|
Posted: Fri Aug 16, 2013 1:37 am
count items to a var |
Hi,
may someone can help:
I have an overview of ampulla in my pocket that looks like this:
Eine ausgepolsterte Ampullentasche, in der sich folgende Ampullen befinden:
0. Eine rote Ampulle
1. Eine blaue Ampulle
2. Eine blaue Ampulle
3. Eine orangene Ampulle
4. Eine blaue Ampulle
5. Eine rote Ampulle
How can i trigger on this and so that i have an overview how many of every colour i have?
I tried it with this:
#trigger { %d. Eine (%w) Ampulle}{#va %1 @%1+1 #class AnzAmpullen}
but with this the value of the var is blaue1..
Any ideas?
Regards
Geggs |
|
|
|
Geggs Beginner
Joined: 13 Aug 2013 Posts: 14
|
Posted: Fri Aug 16, 2013 1:38 am |
why is my post from 2013? i just opened the thread...
|
|
|
|
Shalimar2 Newbie
Joined: 16 Aug 2013 Posts: 8
|
Posted: Fri Aug 16, 2013 9:59 pm |
Minor issues with our host server.
As for the code issue.... due excuse my lack of knowledge with German.
With the trigger as you show it, i would likely use a database variable.
#trigger { %d. Eine (%w) Ampulle} {
$count=@AnzAmpullen.%1
$count=($count+1)
#ADDKEY AnzAmpullen %1 $count
}
Then to see how many of a given color you have you would reference, for example: @AnzAmpullen.rote |
|
|
|
Geggs Beginner
Joined: 13 Aug 2013 Posts: 14
|
Posted: Fri Aug 16, 2013 11:29 pm |
Thanks for your reply!
the funny Thing is, it don't work for the first entry but for the other ones.
In my example i get three entries:
rote (red) value .rote11
orangene( orange) value 1
blaue (blue) value 3
Any idea why this happens? |
|
|
|
Shalimar2 Newbie
Joined: 16 Aug 2013 Posts: 8
|
Posted: Sat Aug 17, 2013 12:19 am |
Slight glitch in referencing because it was the creation of a new variable, much less a database variable.
the first reference of '@AnzAmpullen.%1' while it still has a null value would translate to:
Since CMUD autotypes its variables it assumes that is a string, and concatenates instead of performing math on a null value.
Once it has keys this is no longer an issue and it properly expands to a null value, or 0. |
|
|
|
Shalimar2 Newbie
Joined: 16 Aug 2013 Posts: 8
|
Posted: Sat Aug 17, 2013 12:57 am |
to get around this we can change the code like so:
#trigger { %d. Eine (%w) Ampulle} {
$count=%eval(%db(@AnzAmpullen,%1)+1)
#ADDKEY AnzAmpullen %1 $count
} |
|
|
|
|
|