Discuss Scratch

dusty22
Scratcher
100+ posts

2 List suggestions: checking values of variables in a list, and linear searching of lists

My 1st suggestion - List Items that are Variables Report Variable's Value

Basically, I noticed something I would find very helpful, that lists are currently unable to do. Maybe it's not possible to have this, but I'd figure I'd ask. I have a list in a project, that has items with names of variables I've created.

For example:
List -
1. variable1
2. variable2
3. variable3
{/endlist}

And I want to use it like so. If < (item | 1 ^ | of List) = 0 > Then… or If < (item | 1 ^ | of List) = 1 > Then…

But you can't. Because (item | 1^ | of List) will always equal “variable1”. It can never report the value of variable1, only the name of the item in item# X of the list. Basically, the use I'd find in this is basically a list-searching script the checks a bunch of variables through a linear search of the list rather than using a huge grouping of “Or” operators or nested If statements checking variables.


My 2nd suggestion - Linear Searching/Checking of a List using (item | any ^ | of list)

This touches on what I was just talking about, relating to linearly searching/checking a list. Basically, all we have now is (item | random ^ | of List). This is useful sometimes but other times it is inefficient and ineffective. If you to use this to check an entire list you can but depending on what the script does you may have a small percentage of error.

I'd like to see (item | any ^ | of List) return but with a different function (as I believe “random” is just the original “any” renamed). It would cycle through a list linearly (as in one by one from top to bottom) checking/reporting each list item. It would basically cycle through a list in a straight line instead of randomly pulling out variables.

This can be worked around but with lists more than 2-3 items long it defeats the purpose because at that point it'd be more efficient to use nested If statements or grouped Or operators.

Last edited by dusty22 (Aug. 12, 2013 14:24:39)


Like the Megaman X series? Want to make Megaman games in Scratch? Check out my studio here, The Megaman X Scratch Engine.
turkey3
Scratcher
1000+ posts

2 List suggestions: checking values of variables in a list, and linear searching of lists

1. Do you mean inserting a variable into a list item? I'm a bit confused
2. Yeah, I think the reason they changed item any to random was because of the confusion that “if any item = string”. But what if you don't use item any in an equal statement? What if you set a variable to item any of a list? Which item would it choose? Whereas in the equal statement it checks all ?

ProdigyZeta7
Scratcher
1000+ posts

2 List suggestions: checking values of variables in a list, and linear searching of lists

So for #1 you'd want something like: (variable [ ])
If I put in, say, “variable1” into the [ ], it would report the value of “variable1”, and if I put in “variableABC” it would report the value of “variableABC” and so on… If there is no variable with the inputted name, it would return null.

And, yes, there is a workaround, though it requires two lists: one for names, the other for values.

But hey, I think this idea is great. Support!

As for #2, I suggested that before but didn't get much support because it was confusing. For instance, I wanted to use “say (item (any v) of List)”, but what would it say?



dusty22
Scratcher
100+ posts

2 List suggestions: checking values of variables in a list, and linear searching of lists

As for my 1st suggestion:
You know how you can put the names of sprites in a list to keep tabs on them?

Like you can check to see if a sprite is touching any of the sprites in the list by using “If <touching (item | random ^ | of ListofSprites)>”. Basically it'd be a similar thing except with variables.

Like I could run through a list and have it check to make sure the values of variables 1-20 are all “0” or all “1” or if one variable is “20” and so on.

EDIT: @ProdigyZeta
Yeah I like your suggestion. It'd be confusing if a list item wasn't set aside as being a “variable” item because some people whose list items were named the same as a variable it would report the value of the variable instead of the contents of that list item even if they didn't want it to.


2nd suggestion:
Perhaps it could be disabled for other uses than being inside boolean blocks. Or it could be a boolean style block itself that checks for a specific value (such as <item any of list = value?>.

Last edited by dusty22 (Aug. 13, 2013 14:16:28)


Like the Megaman X series? Want to make Megaman games in Scratch? Check out my studio here, The Megaman X Scratch Engine.
dusty22
Scratcher
100+ posts

2 List suggestions: checking values of variables in a list, and linear searching of lists

*Bump*

So, I'd REALLY like to see this. Anyone else support? The only reason I would think this shouldn't be implemented is if it's not something that can actually be done in other programming languages, as in having values of an array (which is what a list is) point to variables or have secondary values.

Like the Megaman X series? Want to make Megaman games in Scratch? Check out my studio here, The Megaman X Scratch Engine.
dusty22
Scratcher
100+ posts

2 List suggestions: checking values of variables in a list, and linear searching of lists

Aww, no one else likes this idea? Not the end of the world, but it'd add new function to using lists for me.

Like the Megaman X series? Want to make Megaman games in Scratch? Check out my studio here, The Megaman X Scratch Engine.
fleurymarc
Scratcher
71 posts

2 List suggestions: checking values of variables in a list, and linear searching of lists

dusty22 wrote:

… I have a list in a project, that has items with names of variables I've created.

For example:
List -
1. variable1
2. variable2
3. variable3
{/endlist}

And I want to use it like so. If < (item | 1 ^ | of List) = 0 > Then… or If < (item | 1 ^ | of List) = 1 > Then…

But you can't. Because (item | 1^ | of List) will always equal “variable1”. It can never report the value of variable1, only the name of the item in item# X of the list. Basically, the use I'd find in this is basically a list-searching script the checks a bunch of variables through a linear search of the list rather than using a huge grouping of “Or” operators or nested If statements checking variables.


Why the extra step? Why not just directly store the variable values in the list?



Marc.

My Projects, in development:
Game mechanics test for Tank Wars
Partial clone of Asteroids
Foundation for future card games: Card Game base
eaglgenes101
New to Scratch
100+ posts

2 List suggestions: checking values of variables in a list, and linear searching of lists

You're talking about references?
(references are where theres some variable that refers to some other variable)
dusty22
Scratcher
100+ posts

2 List suggestions: checking values of variables in a list, and linear searching of lists

fleurymarc wrote:

Why the extra step? Why not just directly store the variable values in the list?

As not to confuse between the string stored in the list item and the variable it represents.

eaglgenes101 wrote:

You're talking about references?
(references are where theres some variable that refers to some other variable)

I guess kinda. You already have it for sprites where a list item with the same name as a sprite represents it, so I thought why not with variables?

Like the Megaman X series? Want to make Megaman games in Scratch? Check out my studio here, The Megaman X Scratch Engine.

Powered by DjangoBB