|
demonfox12 Beginner
Joined: 28 Dec 2011 Posts: 11
|
Posted: 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? |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: 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 |
|
|
|
demonfox12 Beginner
Joined: 28 Dec 2011 Posts: 11
|
Posted: 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?
|
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: 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 |
|
|
|
demonfox12 Beginner
Joined: 28 Dec 2011 Posts: 11
|
Posted: 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? |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: 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 |
|
|
|
demonfox12 Beginner
Joined: 28 Dec 2011 Posts: 11
|
Posted: 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! |
|
|
|
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
Posted: 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, " ")} |
|
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Fri Jun 19, 2015 8:25 pm |
Oh yes, I forgot about that method.
|
|
_________________ Discord: Shalimarwildcat |
|
|
|
|
|