How do you replace an item in a listview with a particular phrase the press of one button?

Would I add this code to the one dora_paz suggested? If not what would it look like?

Instead of for each item in list use for each number from 1 to lenght of list by 1

I'm still having trouble with this, for example, I put "forward" in the piece box and I put "back" in the replacement box. I copied and pasted this same thing but this time I put "back" in the piece box and then I put "forward" in the replacement box. There seems some kind of error.

Can you help me please

I see your logic error in your Flip button.
You call the procedure that changes all your Forwards to Backs,
then you call the procedure that changes all your Backs to Forwards.

It reminds me of the old magic trick joke where the person pretending to be a magician wraps his hand around a coin and announces he will transport the coin to his other hand magically. Then he announces he will transport it back to the original hand. (He has not opened either hand to the audience.) He opens his hands, and the coin is exactly where it was at the start of the trick.

What you need is the ELSE branch of the IF/THEN block, using just a single procedure instead of two procedures. In the new Flip procedure, you walk through all the indexes 1 to length of list, like you did in your other procedures. But at each index, you have this IF/THEN/ELSE test:

if item at index n = 'Forward' then
   replace it with 'Back"
ELSE if item at index n = 'Back' then
   replace it with 'Forward'

controls_if

1 Like

Is it possible if u could show me using blocks, sorry I am new to this and am really confused haha

Please download and post each of those event block(s)/procedures here ...
(sample video)

There is quite alot is it alright if I just export the whole project?

I only need the two flip procedures.


P.S. These blocks can be dragged directly into your Blocks Editor workspace.

See A way to group projects by theme - #10 by ABG
for a demo.

Thank you so much, but would this work for the other directions? I plan on including Right, Left, Forward Right, Forward Left, Back Left, Back Right

It's possible to add extra ELSE clauses to the IF/THEN block using the blue Mutator button, turning it into a ladder, with one rung for each of your 6 (?) values and their opposite values.

mutator

These three seem to be causing each other problems can you tell me whats going on?



If you want to flip all possibilities with a single button, you have to combine all the flip combinations into just one procedure with a single long if/then/elseif ladder covering all possible flips.

Otherwise those procedures would conflict with one another if you call more than one of them.

By the way, 'Forward Right' contains 'Right', which may not be what you intended. In that case use text '=' for the comparison, or check for 'Forward Right' earlier in the if/then/elseif ladder than 'Right'.

Once you hit a true test in a long if/then/elseif ladder, you fall off the ladder and skip the other tests.

What would you recommend here?

Swap the first and last branches, so the compound items get tested first.

1 Like

still will not work, right-forward becomes front

Here is a totally different approach.
You may need to tweak the text blocks to match what you actually use as values, because this relies on a complete match in its table lookup approach:


This approach uses a lookup table (a dictionary) of values to replace and replacement values, to feed the replacement process while walking through the list items number by number.

The replacement will use the original value as the replacement value whenever it finds an item it can't find in the keys of the dictionary.

If I missed or misspellled any keys/values in the dictionary of replacements, feel free to fix them.

P.S. These blocks can be dragged directly into your Blocks Editor workspace.

See A way to group projects by theme - #10 by ABG
for a demo.