-
Notifications
You must be signed in to change notification settings - Fork 25
Access object field in a loop #87
Comments
Try using the condition syntax. It should work similarly to this: <textbutton color="{? '{element}' = 'x' ? red : default}">{element}</textbutton> You'd have to check if conditions support executing methods, but I'm positive that they just might. |
Also, loops support going through multiple collections at once. While it isn't an ideal solution, you can also do something like this: // Java 8-ish pseudo-code:
@LmlAction("blocksWritten")
public Array<Boolean> getBlocksWrittenStatus() {
return level.blocks.map(Block::isWritten);
} <:foreach element="$blocks" isWritten="$blocksWritten">
<textbutton color="{? {isWritten} ? red : white}">{element}</textbutton>
</:foreach> |
Thank you for your kind response. 1. Workaround but not a solutionThis 'x' comparison would be a workaround, I know that. But, there are going to be more booleans than just 2. Obfuscation?I've seen between threads that obfuscation matters so Java things should be named with
Thus, I think either the macro should be "fixed" (please don't) or field access from a template (stated in this thread) should be supported :) 3. RedrawHowever, the worst thing is I realized all of this probably won't automatically update since there is no change detection. What would be the way to properly redraw some elements (taking fresh data from Java part), then? I'm sorry for asking so many things but it's all related and I'd like to keep the same context. |
I'm sorry to hear that. If field access does not work, I'm afraid you're stuck with the workarounds or doing part of the job in Java, as LML is in maintenance mode.
Field access is somewhat supported, as I recall, in a sense that you can access a field similarly to how you would invoke a method: with
You should implement your listeners in Java. All properties that are available in LML, are simple Java methods that you can call in your views. Look into
It's OK, I'm happy to help. |
Current state
I have a collection of objects, this is working:
Goal
I'd like to colorize "x" blocks to red based on
isWritten
field.Problem
Accessing the
isWritten
field is the unknown to me. How do I do that?I thought about 2 ways:
element
(or index) to a method to evaluate itThe text was updated successfully, but these errors were encountered: