Discuss Scratch

PeterGaming
Scratcher
9 posts

Lists

Hello, am I able to put multiple variables into one line in a list or am I able to put lists inside of lists. I am working on a huge database for a hobby, I have many lists containing things such as dates, times, numbers etc. Am I able to make a new list and combine variables from other lists into a master list or is this not possible? Thanks
mstone326
Scratcher
1000+ posts

Lists

I believe you can use the join blocks to put multiple variables or other list items a single master list item. Maybe use some kind of common separator so you can easily break it back in to appropriate data.

Last edited by mstone326 (Aug. 5, 2017 20:17:35)


High School Athletic Director / Middle School Tech Teacher / High School Baseball Coach
Kung Fu by Nintendo 1984 - https://scratch.mit.edu/projects/369994801/
Taco Defense - Speed Typing - https://scratch.mit.edu/projects/316795450/
Halloween Boss Battle - Taking Back our Woods - https://scratch.mit.edu/projects/257155118/
Almost Pong - https://scratch.mit.edu/projects/656276979/
Studio - My Best Projects - https://scratch.mit.edu/studios/4125978/
Forum Help Project Examples - https://scratch.mit.edu/studios/4133335
PeterGaming
Scratcher
9 posts

Lists

mstone326 wrote:

I believe you can use the join blocks to put multiple variables or other list items a single master list item. Maybe use some kind of common separator so you can easily break it back in to appropriate data.
Thanks, I will test this later!
mstone326
Scratcher
1000+ posts

Lists

Is something like this what you are looking for? Then you can use an index variable to go through each letter until ; and then extract your data again if needed.

https://scratch.mit.edu/projects/170576022/

High School Athletic Director / Middle School Tech Teacher / High School Baseball Coach
Kung Fu by Nintendo 1984 - https://scratch.mit.edu/projects/369994801/
Taco Defense - Speed Typing - https://scratch.mit.edu/projects/316795450/
Halloween Boss Battle - Taking Back our Woods - https://scratch.mit.edu/projects/257155118/
Almost Pong - https://scratch.mit.edu/projects/656276979/
Studio - My Best Projects - https://scratch.mit.edu/studios/4125978/
Forum Help Project Examples - https://scratch.mit.edu/studios/4133335
PeterGaming
Scratcher
9 posts

Lists

mstone326 wrote:

Is something like this what you are looking for? Then you can use an index variable to go through each letter until ; and then extract your data again if needed.

https://scratch.mit.edu/projects/170576022/

Yeah, it worked, but something doesn't seem to be working with the
<[ v] contains [thing] ?>
block. I am trying to search for a specific part of the data in the list but it doesn't work. Here's the link to the project so I don't look confusing: https://scratch.mit.edu/projects/170572457/

Press s when you get onto the project, then type date, then enter 20170412, then it should say worked but instead it says didn't work? And “20170412” is in the master list (called TOPS)

Last edited by PeterGaming (Aug. 5, 2017 20:43:40)

mstone326
Scratcher
1000+ posts

Lists

That block is a boolean, it only returns true or false. Let me check your link now.

Edit: Checked it, you have to create a variable, called index typically, and have that variable change by 1 to cycle through the list items. I have a project in my profile that shows how to do that. I'll find it and post it here.

So after the user types what they are looking for, the current script will just return true or false. But to find it you'll have to use index and repeat until item index = answer.

Give me a sec, I'll find my index example

COuldn't find it but I used an example project shell for my students and adapted it. Type a US state and it will change index to find it in the list. See if this helps.
https://scratch.mit.edu/projects/170576822/#player

Last edited by mstone326 (Aug. 5, 2017 21:00:59)


High School Athletic Director / Middle School Tech Teacher / High School Baseball Coach
Kung Fu by Nintendo 1984 - https://scratch.mit.edu/projects/369994801/
Taco Defense - Speed Typing - https://scratch.mit.edu/projects/316795450/
Halloween Boss Battle - Taking Back our Woods - https://scratch.mit.edu/projects/257155118/
Almost Pong - https://scratch.mit.edu/projects/656276979/
Studio - My Best Projects - https://scratch.mit.edu/studios/4125978/
Forum Help Project Examples - https://scratch.mit.edu/studios/4133335
PeterGaming
Scratcher
9 posts

Lists

mstone326 wrote:

That block is a boolean, it only returns true or false. Let me check your link now.

Edit: Checked it, you have to create a variable, called index typically, and have that variable change by 1 to cycle through the list items. I have a project in my profile that shows how to do that. I'll find it and post it here.

So after the user types what they are looking for, the current script will just return true or false. But to find it you'll have to use index and repeat until item index = answer.

Give me a sec, I'll find my index example

COuldn't find it but I used an example project shell for my students and adapted it. Type a US state and it will change index to find it in the list. See if this helps.
https://scratch.mit.edu/projects/170576822/#player

I seem to have found out that you actually can't search for keywords in a single line, as it seems I can only locate x by typing its full value in, for instance we had a line with the date and various other info, then I created a new line with the date only, used your index code, and it skipped the lines with all the info and went straight to the line with only the date in it.

Edit: Then when I don't have the line with only the date, it says its not in the list

Last edited by PeterGaming (Aug. 5, 2017 21:26:19)

mstone326
Scratcher
1000+ posts

Lists

Make sure you put a parameter to seach for index that it can't go higher than the length of the list. I'm sure there is a way to search the single line code using letter 1 of world block in operators. Make a separate index and repeat until your separator and see if that part of the entry is there. Using the letter 1, or letter new index of answer, will search character by character.

May need one of the heavy hitters to weight on this one. But I'll try to work it out, repeat letter new index of answer until letter new index = (your separator). If that = the first part of entry index, good, else, repeat that for part 2 of entry index, same, then part 3….. all the way through your list.

High School Athletic Director / Middle School Tech Teacher / High School Baseball Coach
Kung Fu by Nintendo 1984 - https://scratch.mit.edu/projects/369994801/
Taco Defense - Speed Typing - https://scratch.mit.edu/projects/316795450/
Halloween Boss Battle - Taking Back our Woods - https://scratch.mit.edu/projects/257155118/
Almost Pong - https://scratch.mit.edu/projects/656276979/
Studio - My Best Projects - https://scratch.mit.edu/studios/4125978/
Forum Help Project Examples - https://scratch.mit.edu/studios/4133335
PeterGaming
Scratcher
9 posts

Lists

mstone326 wrote:

Make sure you put a parameter to seach for index that it can't go higher than the length of the list. I'm sure there is a way to search the single line code using letter 1 of world block in operators. Make a separate index and repeat until your separator and see if that part of the entry is there. Using the letter 1, or letter new index of answer, will search character by character.

May need one of the heavy hitters to weight on this one. But I'll try to work it out, repeat letter new index of answer until letter new index = (your separator). If that = the first part of entry index, good, else, repeat that for part 2 of entry index, same, then part 3….. all the way through your list.

Would the seperator be 9 since “20170412” has 8 characters? This is very difficult to code
mstone326
Scratcher
1000+ posts

Lists

In my first example I put a ; in between each entry so I had a clear separator. But if each “section” of the entry is a a consistent length then you could use a numerical repeat. I'm sure there is an easier way to do this but may need one of the more experienced Scrachers. In the meantime I'll try to work something out.

For my clarification, when a user inputs a date what should the program return?

Thinking you could use a custom block and add 3 strings to it and have it search that way. Could set string1 to item index of date, etc. Then repeat length of string1, letter new index and compile that and see if that matches.

define (string1)(string2)(string3)

Last edited by mstone326 (Aug. 5, 2017 22:00:45)


High School Athletic Director / Middle School Tech Teacher / High School Baseball Coach
Kung Fu by Nintendo 1984 - https://scratch.mit.edu/projects/369994801/
Taco Defense - Speed Typing - https://scratch.mit.edu/projects/316795450/
Halloween Boss Battle - Taking Back our Woods - https://scratch.mit.edu/projects/257155118/
Almost Pong - https://scratch.mit.edu/projects/656276979/
Studio - My Best Projects - https://scratch.mit.edu/studios/4125978/
Forum Help Project Examples - https://scratch.mit.edu/studios/4133335
PeterGaming
Scratcher
9 posts

Lists

mstone326 wrote:

In my first example I put a ; in between each entry so I had a clear separator. But if each “section” of the entry is a a consistent length then you could use a numerical repeat. I'm sure there is an easier way to do this but may need one of the more experienced Scrachers. In the meantime I'll try to work something out.

For my clarification, when a user inputs a date what should the program return?

Thinking you could use a custom block and add 3 strings to it and have it search that way.

define (string1)(string2)(string3)

I've understood your solution better, turns out my seperator was actually a spacebar I'll try and think of how to do this, I'll bump this tomorrow if I'm stuck but Thanks loads!
MineLox92Videos
Scratcher
100+ posts

Lists

PeterGaming wrote:

Hello, am I able to put multiple variables into one line in a list or am I able to put lists inside of lists. I am working on a huge database for a hobby, I have many lists containing things such as dates, times, numbers etc. Am I able to make a new list and combine variables from other lists into a master list or is this not possible? Thanks
Yes:
add (join (Hobby 1) (join [: ] (Time))) to [Hobby 1 and Time v]
set [Hobby 1 and Time v] to (item (1 v) of [Hobby 1 and Time v] :: list)
add (Hobby 1 and Time) to [Total Hobbies v]

Repeat for each hobby (This is just a suggestion)

Last edited by MineLox92Videos (Aug. 6, 2017 00:12:45)

gtoal
Scratcher
1000+ posts

Lists

packing different fields into a single string as suggested above may be conceptually simpler but adding and removing becomes a nightmare.

I would suggest some combination of these:

for structure fields, use parallel arrays, eg “item index of whatever_colour”, “item index of whatever_weight”

Or…

have constants that are the offset within a record, eg
COLOUR=0
WEIGHT=1
OBJECTSIZE=2

item whatever+COLOUR of array
item whatever+WEIGHT of array
whatever = whatever + OBJECTSIZE steps on to the next element (rather than adding 1)

this lets you use the same array for everything, which lets you do things such as LISP style linked lists (using indexes for pointers)

there's no type checking whatsoever of course - this _is_ Scratch after all - but by using a flat array as a substitute for ram and effectively hand-compiling structs and arrays and pointers down to basic Scratch objects, you can simulate any complex data structure from higher level languages.

You just have to be _very_ careful. Eg implement ‘magic numbers’ to tag structures, and check them all the time, to detect faulty accesses during development. You can take all that out in production once your code is well tested. Throw in a few custom blocks to set and to get values and mistakes become less likely and the code should be a bit more readable.

Last edited by gtoal (Aug. 6, 2017 18:41:12)

-Fornax-
Scratcher
100+ posts

Lists

add (join (variable 1) (variable 2)) to [list v]

Last edited by -Fornax- (Aug. 7, 2017 08:50:34)


TheArcadeGuy
Scratcher
100+ posts

Lists

-Fornax- wrote:

add (join (variable 1) (variable 2)) to [list v]

This wouldn't work. More code is needed to do what PeterGaming is asking for.



Powered by DjangoBB