|
Articval Novice
Joined: 01 Jun 2005 Posts: 47
|
Posted: Sat Nov 01, 2008 10:40 pm
[2.37] #if command inside #forall, failing |
Hi!
I explain myself badly when talking about programming, so I will put examples of what I think it should do and what it does.
#forall @list {#if %i=cheese {#echo yeah}}
This forall was not working for me, the exact error was that I had an extra bracet, then I remove the bracet, and it wont work correcly either.
What I had to do to 'solve' it was to get an alias this way:
#forall @list {aliasname %i}
#alias aliasname {#if %1=cheese {#echo yeah}}
Hope this was not already posted, and I would like to know if this is a bug or if its supoused to work that way, thankyou! |
|
|
|
Dumas Enchanter
Joined: 11 Feb 2003 Posts: 511 Location: USA
|
Posted: Sat Nov 01, 2008 10:52 pm |
hmm, original worked for me. Which means it makes no sense that the first didn't work and the second didn't. Might you have made a typo on the original one?
Just to be sure, you are expecting that whenever cheese is found on the list, that yeah will be printed. You aren't expecting any thing else to happen right? |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Sat Nov 01, 2008 11:11 pm |
It's generally because CMUD is more strict with commands. It should work either way, but try:
#FORALL @list {#IF (%i="cheese") {#echo yeah}}
will work. Quote the strings, parenthesize the arguments.
Charneus |
|
|
|
Dumas Enchanter
Joined: 11 Feb 2003 Posts: 511 Location: USA
|
Posted: Sun Nov 02, 2008 1:56 am |
Both work charneus, at least for me. But it still doesn't explain why the first one did not work for Articval and his workaround did. Maybe it is the context of how he was using it?
|
|
|
|
Articval Novice
Joined: 01 Jun 2005 Posts: 47
|
Posted: Sun Nov 02, 2008 2:17 pm |
Ok, got the difference:
If you guys do:
#FORALL @listacolores {%i;#IF (%i="yellowgreen") {#echo yeah}}
THAT is what is not going to work :)
If u remove the %i, then works like it should |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Sun Nov 02, 2008 2:30 pm |
That's because you can't start a line with a function.
#FORALL @listacolores {#EXEC {%i};#IF (%i="yellowgreen") {#echo yeah}}
WILL work.
Charneus |
|
|
|
Articval Novice
Joined: 01 Jun 2005 Posts: 47
|
Posted: Sun Nov 02, 2008 2:40 pm |
The more I think I know, the more I know I dont.
Thankyou. |
|
|
|
|
|