|
|
|
06-19-2021, 05:02 AM
|
#1
|
Human being with feelings
Join Date: Sep 2018
Location: China
Posts: 565
|
Question about if...elseif in EEL
Are these codes the same as each other?
LUA:
Code:
a=3
if a>0 then
if a==1 then
b=1
elseif a==2 then
b=2
elseif a==3 then
b=3
else
b=4
end
end
EEL:
Code:
a=3;
a>0 ? (
a==1 ? b=1;
a==2 ? b=2;
a==3 ? b=3 : b=4
);
Or:
Code:
a=3;
a>0 ? (
a==1 ? b=1:
a==2 ? b=2:
a==3 ? b=3:
b=4
);
Last edited by dsyrock; 06-19-2021 at 10:29 AM.
|
|
|
06-19-2021, 10:14 AM
|
#2
|
Human being with feelings
Join Date: Sep 2008
Location: Sweden
Posts: 7,432
|
Why not just try it? That would be quicker than asking here
Your Lua code is missing an "end" after "b=4", and I think your eel code must have a semi-colon after "b=4" in both cases.
Code:
value of b
a | Lua | EEL 1 | EEL 2
---+-----+-------+-------+
0 | 0 | 0 | 0
1 | 1 | 4 | 4
2 | 2 | 4 | 4
3 | 3 | 3 | 4
4 | 4 | 4 | 4
5 | 4 | 4 | 4
Apart from this, I think there is also the difference that in Lua, once the if or an elseif is true, the rest is not executed. In your EEL code this is not the case, all if-clauses are tested whatever the value of a (I think).
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
|
|
|
06-19-2021, 10:28 AM
|
#3
|
Human being with feelings
Join Date: Sep 2018
Location: China
Posts: 565
|
Quote:
Originally Posted by Fabian
Why not just try it? That would be quicker than asking here
Your Lua code is missing an "end" after "b=4", and I think your eel code must have a semi-colon after "b=4" in both cases.
Code:
value of b
a | Lua | EEL 1 | EEL 2
---+-----+-------+-------+
0 | 0 | 0 | 0
1 | 1 | 4 | 4
2 | 2 | 4 | 4
3 | 3 | 3 | 4
4 | 4 | 4 | 4
5 | 4 | 4 | 4
Apart from this, I think there is also the difference that in Lua, once the if or an elseif is true, the rest is not executed. In your EEL code this is not the case, all if-clauses are tested whatever the value of a (I think).
|
Thanks. Sorry about the typo in LUA, already fixed. I'm writing a jsfx plugin, and keep getting weird results. Then I suspect I'm using the (if else) a wrong way. I have quite little experience in eel.
So if I need the eel code run totally the same as the lua one, how can I modify it?
Last edited by dsyrock; 06-19-2021 at 10:34 AM.
|
|
|
06-19-2021, 11:24 AM
|
#4
|
Human being with feelings
Join Date: Sep 2008
Location: Sweden
Posts: 7,432
|
Quote:
Originally Posted by dsyrock
So if I need the eel code run totally the same as the lua one, how can I modify it?
|
I did not try it, but I think this will work:
Code:
a=3;
a>0 ? (
a==1 ? b=1 : // colon here instead of semi-colon
a==2 ? b=2 :
a==3 ? b=3 : b=4;
);
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
|
|
|
06-19-2021, 01:50 PM
|
#5
|
Human being with feelings
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,784
|
For clearness I would something like
Code:
a>0 ? (
a==1 ? (
b=1;
) : a==2 ? (
b=2;
) : a==3 ? (
b=3;
) : (
b=4;
);
);
-Michael
|
|
|
06-19-2021, 07:12 PM
|
#6
|
Human being with feelings
Join Date: Sep 2018
Location: China
Posts: 565
|
Thanks, all of you!
|
|
|
06-20-2021, 07:25 AM
|
#7
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
Or a less verbose version:
EEL:
Code:
a>0 ? ( a<4 ? b=a : b=4 );
Comparing EEL to LUA take this into account (applies to all code snippets):
in case a <= 0, b will be equal to 0 for EEL, while for LUA it will be non-existent (nil).
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 04:51 PM.
|