This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-06-14 12:48:35

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Altering a letter of "stacked" array

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)


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#2 2012-06-14 13:25:26

SciTecCf
Scratcher
Registered: 2011-11-23
Posts: 1000+

Re: Altering a letter of "stacked" array

Wait, I'll type one up.


http://bit.ly/LCZEJRhttp://bit.ly/LSONcOhttp://bit.ly/LF3vIc
http://trinary.site40.net/images/scratchrank.php?username=SciTecCf&display=small

Offline

 

#3 2012-06-14 13:27:49

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Altering a letter of "stacked" array

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.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#4 2012-06-14 13:30:45

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Altering a letter of "stacked" array

AtomicBawm3 wrote:

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.

I'm trying that now.


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#5 2012-06-14 14:19:05

SciTecCf
Scratcher
Registered: 2011-11-23
Posts: 1000+

Re: Altering a letter of "stacked" array

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.  wink

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)
end
I didn't test it, so it might not work.

Last edited by SciTecCf (2012-06-14 14:22:54)


http://bit.ly/LCZEJRhttp://bit.ly/LSONcOhttp://bit.ly/LF3vIc
http://trinary.site40.net/images/scratchrank.php?username=SciTecCf&display=small

Offline

 

#6 2012-06-14 14:39:51

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Altering a letter of "stacked" array

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.  wink

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)
end
I 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)


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

Board footer