If you are requesting technical assistance with Twine, please specify:
Twine Version: 2.3.14
Story Format: Sugarcube 2.34.1
in my project the position of a unit inside the party is very important, so i want the player to be able to change them around at will.
the code parts look like this.
example unit defined as object/datamap (don’t know the difference):
i want to add an option where theres a second link under the first one that allow the player to move that unit to a specific place in the array,
because certain skills will will bahave differently depending on the position of the unit, like a “shield” skill is supposed to be most effective in the front.
i also want it to change inside the array beacuse that way the loop above serves as a visual represantation of the units order.
For the record, that’s a generic JavaScript object, not a JavaScript Map object (a “datamap” is a similar Harlowe concept).
Anyways, if you want to swap two array elements, then it’s just a three step shuffle of data. Simply copy one array element to a temporary variable, then overwrite that element with the value in the other element, and then overwrite the element that wasn’t overwritten yet with the value in the temporary variable.
Your code for that within your <<for>> loop might look something like this:
This works exactly like i wanted it to, thank you!
It does mess with my .twocolumn setup but i wanted to replace that with a table anyway, so i guess i’ll work on that next.
Ah, then I should mention that SugarCube doesn’t make it easy to build tables using a <<for>> loop. The trick to get around the problem is to simply build the whole table as a string within a temporary variable and then, once the table is complete, simply print out that string.
No, I’m referring to the fact that SugarCube complains if you create an HTML element like <tr> without also creating a </tr> at the exact same time. That can make building up complex HTML objects (like tables) from pieces difficult. That’s why it’s easier to just add it all to a string and then print that string out, since it builds the whole table at once.
I understand the point of the validation check, but it can be annoying when, instead of helping, it gets in the way of things and you have to do workarounds like this.
I’m not saying that there aren’t ways around it, and I don’t remember specific circumstances of the times where this has happened in the past off the top of my head, but it’s still annoying when you’re trying to do something which is the equivalent of:
<<= "<label>test">>
<<= "</label>">>
and you can’t, because it throws a “Error: cannot find a closing tag for HTML <label>” error message when trying to run the first line. When that happens it’s like, “Hey! Just run the next line of code! It’s right there!” It’s frustrating.
If I come across one of the cases where this was a problem I encountered, then I’ll let you know, but it’s still annoying, IMHO.