Channel Elements -- too many attacks?

Any new ideas that you'd like to see in the next version of ToME 2.x.x post here

Moderator: Moderator

What to do?

Leave Channel Elements as is
1
11%
Replace some attacks with other spells
2
22%
Replace all the attacks
0
No votes
Uhm ... Manathrust! :P
2
22%
I like casting Geyser lots of times
0
No votes
Polls are silly :)
4
44%
 
Total votes: 9

Message
Author
Nerdanel
Sher'Tul
Posts: 1461
Joined: Mon Jul 07, 2003 5:22 pm
Location: Finland

#46 Post by Nerdanel »

I'm a C++ lover who has had to program in ASP and Vbscript lately. (Ugh!) I've been using parentheses liberally even in places where they aren't completely necessary. They don't affect the execution of the program and make it look better and clearer to me. I think the situation is probably similar with LUA (which I haven't yet tried).

But I really do think curly braces beat keywords. Those braces are decipherable at a very brief glance and I don't know why people would forget them any more than the equivalent keywords. I myself forget curly braces very rarely because I always insert them in pairs. Those pesky thens on the other hand...
Zothiqband -- still an Angband variant.

fearoffours
Uruivellas
Posts: 656
Joined: Thu Jul 25, 2002 8:07 am
Location: Leafy East Surrey, UK
Contact:

#47 Post by fearoffours »

can someone explain (in terms someone who can script in lua but not code in C could understand) whatr a trinary conditional operator is please?

darkgod
Master of Eyal
Posts: 10751
Joined: Wed Jul 24, 2002 9:26 pm
Location: Angolwen
Contact:

#48 Post by darkgod »

Trinary operator is sometimes usefull but really quite ugly IMO:

res = (condition) ? true_value : false_value;

Whcih will select the true_valu or false_value based on the condition
[tome] joylove: You can't just release an expansion like one would release a Kraken XD
--
[tome] phantomfrettchen: your ability not to tease anyone is simply stunning ;)

Nerdanel
Sher'Tul
Posts: 1461
Joined: Mon Jul 07, 2003 5:22 pm
Location: Finland

#49 Post by Nerdanel »

a ? b : c;

a is the condition
b is done if a is true
c is done if a is false

Basically the same thing as writing

if (a)
{
b;
}
else
{
c;
}

VBScript has it

if a then
b
else
c
end if

This should be close to how lua does it. (I know it lacks the final if.) I'm not putting up a lua example as I have never more than glanced at it.

I tend to use the long way myself even in C. It takes more lines but is more readable. I was taught in a place in which a lot of weight was put on good coding style.
Zothiqband -- still an Angband variant.

Jules
Halfling
Posts: 117
Joined: Tue Jun 24, 2003 2:40 pm

#50 Post by Jules »

Fo4s:

The trinary operator is (cond ? thenpart : elsepart). It is an expression, not a statement, and it evaluates to whatever the thenpart evaluates to if cond evaluates to true, or whatever the elsepart evaluates to, otherwise.

As for implementing it in lua, try something like

function ifte(cond,t,e) if cond then return t else return e end end

Use it as follows:

ifte(dam-10 < 1,1,dam-10)

add in some more brackets, BenH style, if you prefer.

Of course, ifte is 4 characters long, which is a bit of a pain, but 'if' is a reserved word and 'i' is probably namespace pollution. But you might think of a better name.

You can't actually implement new operators in lua (although you could by modifying the source of lua itself, of course), but you can alter the existing ones. So one might be able to do a tremendous hack with them, but I don't recommend it.

Jules
Halfling
Posts: 117
Joined: Tue Jun 24, 2003 2:40 pm

#51 Post by Jules »

Nerdanel wrote:It takes more lines but is more readable. I was taught in a place in which a lot of weight was put on good coding style.
...which goes back to my original point.

This is rubbish, of course. The '?' version is no 'less readable' if you are used to the '?' operator. Indeed, it is *more* readable and *more* compact. On the other hand, if you are not used to the operator, it is of course less readable.

Just as <<< and << are unreadable if you can't remember which is which.

Syntax is just something you have to get used to. When choosing syntax for a piece of code you might want to be aware of the syntactic prejudices of the code's intended audience, that's all.

Post Reply