Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Geggs
Beginner


Joined: 13 Aug 2013
Posts: 14

PostPosted: 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
Reply with quote
Geggs
Beginner


Joined: 13 Aug 2013
Posts: 14

PostPosted: Fri Aug 16, 2013 1:38 am   
 
why is my post from 2013? i just opened the thread...
Reply with quote
Shalimar2
Newbie


Joined: 16 Aug 2013
Posts: 8

PostPosted: 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
Reply with quote
Geggs
Beginner


Joined: 13 Aug 2013
Posts: 14

PostPosted: 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?
Reply with quote
Shalimar2
Newbie


Joined: 16 Aug 2013
Posts: 8

PostPosted: 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:
Code:
' .rote'


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.
Reply with quote
Shalimar2
Newbie


Joined: 16 Aug 2013
Posts: 8

PostPosted: 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
}
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net