[Question] How do use the for each item puzzle piece
duncanwebb opened this issue ยท 10 comments
I was expecting that the "for each item" to contain the value of the variables the item name for the item. On the sign it displays 0, 0, 0
Also, the import inventory piece only imports the first item. Maybe I need to use multiple item filters.
The idea is to place down a pattern of blocks using a subsequent "for each coordinate" piece.
I might have the wrong idea about what the "for each item" puzzle piece does. Many thanks.
Have to admit I'm not overly familiar with how items in variables work, never having really played with them. However, looking at the code, there isn't any support for displaying variables as items. But that's something that shouldn't be too hard to add...
I do see one mistake in your program: it's not necessary to explicitly Jump back to "Main" at the end of your "subroutine" (bottom right). When you call out via "For Each Item" or "For Each Coordinate", there's an implicit jumpback to the widget after the "For Each" widget (think of the "For Each" widgets like a "GOSUB" from BASIC).
Regarding the import, or more specifically the "Item Assign" widget - it only allows a single item to be assigned to a variable. So in your case, the blocks
variable will be "Dirt" and nothing else. Unfortunately you can't assign a list of items to a variable like that, even though the GUI doesn't prevent it. So in your case, just put the cobble & dirt item filters directly on the Import Items widget and it'll work (assuming your drone has the necessary Inventory Upgrades...).
Or you could use the "For Each Item" piece to repeatedly call the import piece, which should also work, and could be useful if you need to do some more advanced testing on each item as you import it.
I have a feeling item support in variables is something Minemaarten added quite late on, and the concept was never fully fleshed out...
Build 87 should display the item names from the $block
variable on your sign. Do also remove that last jump back to "Main", it's probably messing up your foreach loop...
And build 88 will warn you if you add more than one Item Filter to an Item Assignment widget.
You can use Button widgets on the remote to assign separate values to the X/Y/Z fields. Dropdowns only assign the index of the dropdown element to the X field; they can't modify the Y or Z fields of a variable. I wonder if it would be useful to allow configuration of dropdowns to select which of X/Y/Z to modify?
I'm not sure about clamping the variable between -1 and 1...
Many thanks, I'll remove the jump and test the new changes. I wonder how to limit a variable between -1 and 1, I'd like the x, y and z to be between -1 and 1 and I think the coordinate operator min max should be able to do this and the tests I've done didn't work.
Is it possible to assign the x, y and z from a remote? I could use a dropdown element on a remote and assign a value to one of the three fields. I don't think it is possible.
Here is a non-trivial program to build a wall using a "for each item" https://pastebin.com/hxFtwUAZ
The problem with this program is calculating the next position, it really needs a generator function.
Yes, I think it would be good to be able to set the parts of a coordinate puzzle piece - may be a coordinate control for the remote?
Yeah, I understand python generators - basically a lazy-evaluation mechanism. What I'm not really clear on is how they would be implemented into the drone programming system...
For a sequence a generator would yield the next item in the sequence. For an area the sequence would be the next position so allowing an easy way to place the item.
In the example above the first item is stone, the generator would set pos to the first position in the area and a stone is placed in this position, the next item is a cobblestone and pos would be set to the next position and a cobblestone is placed there, the third item is again stone and the position would be the third position in the sequence.
Generators are more to do with iterating sequences than lazy evaluation.