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
demonfox12
Beginner


Joined: 28 Dec 2011
Posts: 11

PostPosted: Thu Jun 18, 2015 6:59 pm   

Alias Help
 
I've been using Cmud for some time already, and while I'm not a -total- novice at it, I can't begin to fathom how to do what I want to do...

Basically, I have 4 variables. leftarm, rightarm, leftleg, rightleg.

What I would like to do with these is compare their numerical values while storing the name of the variable for further use (%min just tells me what the value is, not the variable) so I could do something like...

if leftleg has the lowest value = attack left leg.

Additionally, while comparing these 4 variables, I want to remove one from the comparison based on a 5th variable (parried) that tells me which limb I can't attack, thus not attacking it.

Is this possible to do?
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Thu Jun 18, 2015 9:45 pm   
 
Something like this should work
Code:
#LOCAL $spot
$value=100
$limbs=right arm|left arm|right leg|left leg
#DELITEM $limbs @parried
#FORALL $limbs {
  $this=%concat("@", %replace(%i, " "))
  #IF ($this<$value) {
    $value=$this
    $spot=%i
    }
  }
attack $spot
_________________
Discord: Shalimarwildcat
Reply with quote
demonfox12
Beginner


Joined: 28 Dec 2011
Posts: 11

PostPosted: Fri Jun 19, 2015 1:24 am   
 
Ok, it took me a little while to figure out what was happening in that (I've never used local variables before). However, I pasted that in and it doesn't seem to be holding the $spot value for 'attack $spot'. Adding #echo $spot test to the line after 'attack spot' returned ' test'. Is there a way around this?
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Fri Jun 19, 2015 2:43 am   
 
I am guessing that my %concat is not properly allowing $this to contain a reference to the appropriate limb variable.
Throw in a '#SAY $this' to test that for me?
Not thinking of a proper way to correct that issue if so though... maybe wrap it in an %eval
_________________
Discord: Shalimarwildcat
Reply with quote
demonfox12
Beginner


Joined: 28 Dec 2011
Posts: 11

PostPosted: Fri Jun 19, 2015 3:41 am   
 
Using #say $this didn't return anything, but using your code, I edited it a little to make it more understandable for me, and now it fires, but improperly..

Code:

#var limbvalue 100 100 A-Test
#var limbs {right arm|left arm|right leg|left leg} {right arm|left arm|right leg|left leg} A-Test
#DELITEM limbs @parried
#cr
#echo Values
#echo rl: @rightleg
#echo ll: @leftleg
#echo ra: @rightarm
#echo la: @leftarm
#echo removing @parried from list.
#FORALL {@limbs} {
  $this=%concat("@", %replace(%i, " "))
  #IF ($this<=limbvalue) {
    limbvalue=$this
    #var spot {%i} {none} A-Test
    #echo $this: @limbvalue}
  }
attack @spot

This outputs with:
Code:
Values
rl: 2
ll: -1
ra: 4
la: 0
removing left leg from list.
@rightarm: 4
@leftarm: 0
@rightleg: 2
attack right leg


Which should clearly return 'attack left arm' since it is 0, right? By it even echoing '@rightleg: 2', that means it returned "2 <= 0" as true, right?
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Fri Jun 19, 2015 4:05 am   
 
That's my point.

$this=%concat("@", %replace(%i, " "))

seems to not be referencing the limb variable, when $this is itself referenced later, but giving us a string that represents the variable instead

Try it with:

$this=%eval(%concat("@", %replace(%i, " ")))
_________________
Discord: Shalimarwildcat
Reply with quote
demonfox12
Beginner


Joined: 28 Dec 2011
Posts: 11

PostPosted: Fri Jun 19, 2015 5:46 am   
 
Yes! Ok, thank you so much:)

I did your change, and I also fixed a mistake I had made (<limbvalue instead of <@limbvalue) and now it works great. Thanks a bunch!
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Fri Jun 19, 2015 11:35 am   
 
That's a very roundabout way to get the contents of each variable, and using %eval should be avoided because it's really slow. This is the proper way to reference a variable dynamically:

Code:
$this=@{%replace(%i, " ")}
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Fri Jun 19, 2015 8:25 pm   
 
Oh yes, I forgot about that method.
_________________
Discord: Shalimarwildcat
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