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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
cosine_omerta
Wanderer


Joined: 14 Oct 2007
Posts: 50

PostPosted: Sun Sep 19, 2010 10:46 pm   

Variable Issue
 
I had some aliases and variables set up so that I could easy tally up some numbers. This worked fine up until about 5 beta versions ago, and suddenly it doesn't work. I kept hoping the next beta would fix it, but no luck. This is what my code looks like:

#if (%1 = "goblin") {#add monster@trynumber.GOBLIN 1}
#if (%1 = "orc") {#add monster@trynumber.ORC 1}

This is used with an alias so that I can type 'tally goblin' and it will add to the the goblin number on trynumber 1, then a trigger changes the trynumber, and I can still use tally for the next trynumber. Then I can see the totals for each trynumber.

This will no longer save the tallies to the trynumbers. This code for saving the totals still works:

#if (%1 = "goblin") {#add monster.GOBLIN 1}

So I assume its the putting the trynumber variable in the monster db variable.

So my question is, does anybody have any suggestions for a workaround or should I keep crossing my fingers the next beta will make it work again?
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon Sep 20, 2010 1:53 am   
 
Surround trynumber.whatever in {} if you want to provide a reference to a monsterX variable.
_________________
EDIT: I didn't like my old signature
Reply with quote
cosine_omerta
Wanderer


Joined: 14 Oct 2007
Posts: 50

PostPosted: Mon Sep 20, 2010 2:15 am   
 
It still doesn't save it to the monster db variable. This is what I tried:

{#add monster@{trynumber.GOBLIN} 1}
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon Sep 20, 2010 3:15 am   
 
Umm, you aren't referencing the @monster variable. You are referencing a variable whose name is the concatenated result of monster and whatever @trynumber.goblin is. For example, if @trynumber.goblin = 6 then your #add command is referencing the @monster6 variable.
_________________
EDIT: I didn't like my old signature
Reply with quote
cosine_omerta
Wanderer


Joined: 14 Oct 2007
Posts: 50

PostPosted: Mon Sep 20, 2010 3:44 am   
 
Not sure what you mean. I'm referencing the monster database variable, as monster2.GOBLIN, or the next variable monster3.GOBLIN, or whatever count trynumber is at. I'm sorry if I'm not saying it properly. The @trynumber is a counter variable and I'm trying to get the numbered monster db variable to be added up, but cMud won't play nice with the monster trynumber being a variable anymore.

Example. If trynumber is 2, which makes it monster2.GOBLIN, and I add 1 to the resulting monster2.GOBLIN, monster2.GOBLIN doesn't increase by 1, it stays at 0.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Mon Sep 20, 2010 3:51 pm   
 
Take a look a this test code. It should do what you want.

Code:
#LOOP 5 {
  #ADDKEY monster%i GOBLIN 0
}

#VAR

#LOOP 5 {
  #VAR trynumber %i
  #add monster@{trynumber.GOBLIN} 1 // This doesn't work
  #add {%concat("monster",@trynumber,".GOBLIN")} 1  // This does
}

#VAR
_________________
Asati di tempari!
Reply with quote
Taz
GURU


Joined: 28 Sep 2000
Posts: 1395
Location: United Kingdom

PostPosted: Mon Sep 20, 2010 6:47 pm   
 
I would imagine that given the further explanation that he want to use #add monster@{trynumber}.GOBLIN 1 instead.
_________________
Taz :)
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23377
Location: Colorado, USA

PostPosted: Mon Sep 20, 2010 6:54 pm   
 
Actually, the proper "official" syntax for this is:
Code:
#LOOP 5 {
  #VAR trynumber %i
  #add %concat("monster",@trynumber).GOBLIN 1
}

It's another example of trying to rely upon implicit concat when you should just be using explicit %concat instead. The part you are trying to concat is "monster" and @trynumber. The ".GOBLIN" is a key reference and really doesn't need to be part of the concat.
Reply with quote
cosine_omerta
Wanderer


Joined: 14 Oct 2007
Posts: 50

PostPosted: Tue Sep 21, 2010 11:37 am   
 
Thanks for all the help! It's awesome that you guys take the time to help crazy people like me.
The %concat usage works perfectly!
Just for reference, the monster@{trynumber}.GOBLIN didn't work either.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum 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