Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How do you locate a line in a list that contains a variable with other text?
- WorldCountries
-
9 posts
How do you locate a line in a list that contains a variable with other text?
In my project I am trying to locate a line in a list that is surrounded by other text.
So, I'm trying to make a command so that you can delete all the chats for the last hour.
Here's the script I've done:
However, it only deletes lines that have only the “hour” variable in it, without any other text.How do I make it so that the script can locate a variable in a line with other text in a script?
So, I'm trying to make a command so that you can delete all the chats for the last hour.
Here's the script I've done:
when this sprite clicked
set (Clicked?) to [Y]
repeat until <not <[Chat] contains (Hour)?>
repeat until <<item (no.) of [Chat]> contains (Hour)?>
change (no.) by [1]
end
delete (no) of [Chat]
end
However, it only deletes lines that have only the “hour” variable in it, without any other text.How do I make it so that the script can locate a variable in a line with other text in a script?
- imfh
-
1000+ posts
How do you locate a line in a list that contains a variable with other text?
You could just make it delete the whole history, which would be more practical and powerful.
If you still want to, you could try something like this. You will need a seperate list that holds the days since 2000 of each chat item.
Also, since you don't have any cloud variables in your project yet to make the chat work, you might want to put a note in the description stating that it isn't functional yet.
If you still want to, you could try something like this. You will need a seperate list that holds the days since 2000 of each chat item.
set [i v] to [1]
repeat until <(item (i) of [timestamps v] :: list) < ((days since 2000) - ((1) / (24)))>
change [i v] by (1)
end
repeat (i) // i is the position of the first item further than a hour away.
delete (last v) of [chat v]
delete (last v) of [timestamps v]
Also, since you don't have any cloud variables in your project yet to make the chat work, you might want to put a note in the description stating that it isn't functional yet.
Last edited by imfh (Nov. 19, 2018 21:53:16)
- Discussion Forums
- » Help with Scripts
-
» How do you locate a line in a list that contains a variable with other text?