I've got a project that uses an array based around items being Y and letters being X(hence "stacked" items), and I need a way of altering a letter of that list, Scratch's basic "replace item () of () with ()" block doesn't allow for this. Any ideas?
Last edited by zammer990 (2012-06-14 12:52:47)
Offline
Easiest way to do it would probably be to transfer all of the letters into a new list, edit the item number, then transfer it back in.
Offline
Okay, so you are going to 2 new lists. Call them "separator" and "lengths".
You will also need 3 variables. One called "loopcounter" another one called "loopcounter2", and another one called "adder".
Use this script. Just remember to replace
(x item)
(y item)and
[Your List v]with their appropriate values.
delete (all v) of [seperator v] delete (all v) of [lengths v] set [loopcounter v] to [1] repeat (length of [Your List v]) set [loopcounter2 v] to [1] add (length of (item (loopcounter) of [Your List v])) to [lengths v] repeat (length of (item (loopcounter) of [Your List v])) add (letter (loopcounter2) of (item (loopcounter) of [Your List v])) to [separator v] end change [loopcounter v] by (1) end set [adder v] to [0] set [loopcounter v] to [1] repeat ((y item) - (1)) change [adder v] by (item (loopcounter) of [lengths v]) change [loopcounter v] by (1) end change [adder v] by (x item) replace item (adder) of [seperator v] with [Whatever] delete (all v) of [Your List v] set [loopcounter v] to [1] set [loopcounter2 v] to [1] set [adder v] to [] //Blank. repeat (length of [lengths v]) repeat (item (loopcounter) of [lengths v]) set [adder v] to (join (adder) (item (loopcounter2) of [separator v])) change [loopcounter2 v] by (1) end add (adder) to [Your List v] set [adder v] to [] //Blank. repeat (item (loopcounter) of [lengths v]) delete (1 v) of [separator v] end change [loopcounter v] by (1) endI didn't test it, so it might not work.
Last edited by SciTecCf (2012-06-14 14:22:54)
Offline
SciTecCf wrote:
Okay, so you are going to 2 new lists. Call them "separator" and "lengths".
You will also need 3 variables. One called "loopcounter" another one called "loopcounter2", and another one called "adder".
Use this script. Just remember to replace(x item)(y item)and[Your List v]with their appropriate values.delete (all v) of [seperator v] delete (all v) of [lengths v] set [loopcounter v] to [1] repeat (length of [Your List v]) set [loopcounter2 v] to [1] add (length of (item (loopcounter) of [Your List v])) to [lengths v] repeat (length of (item (loopcounter) of [Your List v])) add (letter (loopcounter2) of (item (loopcounter) of [Your List v])) to [separator v] end change [loopcounter v] by (1) end set [adder v] to [0] set [loopcounter v] to [1] repeat ((y item) - (1)) change [adder v] by (item (loopcounter) of [lengths v]) change [loopcounter v] by (1) end change [adder v] by (x item) replace item (adder) of [seperator v] with [Whatever] delete (all v) of [Your List v] set [loopcounter v] to [1] set [loopcounter2 v] to [1] set [adder v] to [] //Blank. repeat (length of [lengths v]) repeat (item (loopcounter) of [lengths v]) set [adder v] to (join (adder) (item (loopcounter2) of [separator v])) change [loopcounter2 v] by (1) end add (adder) to [Your List v] set [adder v] to [] //Blank. repeat (item (loopcounter) of [lengths v]) delete (1 v) of [separator v] end change [loopcounter v] by (1) endI didn't test it, so it might not work.
I can't even be sure how it works? You add the lengths of all the items into a list, then it just seems to go a bit crazy?
EDIT
Don't worry, I got one working by adding all the letters from the line into another list, modding the grid and replacing the line with that list
This can be closed now
Last edited by zammer990 (2012-06-14 14:52:29)
Offline