Many games need something to react to several different things or to check if a variable is any of a set. While this is possible like this:
if <<<(value) = (5)> or <(value) = (3)>> or <(value) = (7)>>It's long and cumbersome, it's also possible with lists, but making a list for every check is also long and cumbersome. I suggest a block like this:
<() or ()>this would let you put strings or integers into it and allow this:
if <(value) = <(5) or <(6) or (7)>>>Possibly just as a modification to the current or block, but it would allow far smaller scripts.
Offline
Just add all the values to a list and use
if <[list v] contains (value)>
Last edited by Wes64 (2012-07-03 11:29:27)
Offline
SciTecCf wrote:
What would it report? 6 or 7?
It's trying to check a single value against a set of others, it'd report true if it's equal to any of them.
wes65 wrote:
Just add all the values to a list and use
[scratchblocks]
if <[list v] contains (value)>
True, it's possible, but having a list is cumbersome and this is about making it quicker to do.
Offline
Lists are less cumbersome than what you've got. Also it is easy to add and remove data from the list, while you giant chain of blocks is unwieldy.
And I do not know what you mean by "making it quicker". Scratch can do all these operations in a millisecond.
Offline
I disagree; it's like this in regular programming too and it's a good habit to get into.
Offline
I don't support mainly because it would generate extreme confusion with the actual OR block, and that not a single programming language uses OR operators for strings.
It's just not logical.
To prove my point then, tell me, what would happen if I used that block in a non-boolean?
An acceptable alternative that I still wouldn't like but I wouldn't despise either is extendible equal/unequal blocks that accept any number of alternatives on either side.
However lists are still far less cumbersome and actually have programming logic.
Offline
veggieman001 wrote:
I disagree; it's like this in regular programming too and it's a good habit to get into.
"like this in regular programming"
>>> a = "cats are fun" >>> if a == "goats are fun" or "cats are fun" or 5: print "ok" ok
Just tried it in python.
And for people saying they're not cumbersome, having a large amount of lists can slow your game considerably, because it has to maintain a lot of mutable objects. It also fills up the variables section.
This could also just be a modification to the existing "or" block.
Offline
zammer990 wrote:
And for people saying they're not cumbersome, having a large amount of lists can slow your game considerably, because it has to maintain a lot of mutable objects.
Lists only affect my computer when I save. I can program just as speedily in a game that has 50 lists as I can in a blank project.
Offline
zammer990 wrote:
veggieman001 wrote:
I disagree; it's like this in regular programming too and it's a good habit to get into.
"like this in regular programming"
Code:
>>> a = "cats are fun" >>> if a == "goats are fun" or "cats are fun" or 5: print "ok" okJust tried it in python.
And for people saying they're not cumbersome, having a large amount of lists can slow your game considerably, because it has to maintain a lot of mutable objects. It also fills up the variables section.
This could also just be a modification to the existing "or" block.
In Visual Basic (which I use), it says something like "string cannot be converted to boolean", whan it tries to evaluate "cats are fun" as a boolean. At least I think it does that (I haven't tested it).
Offline
I'm sure that what you tried in Python worked, but because you didn't thoroughly test it.
Most of the time using the OR operator in that manner will NOT give a compiler error. This is because intelligent languages will allow strings and integers to be automatically converted to booleans.
Therefore, the code IF VARIABLE = VALUE or VALUE2 or VALUE3
reads as
-does variable = value? if yes, evaluate IF
-does value2 convert to TRUE? if yes, evaluate
-does value3 convert to TRUE? if yes, evaluate
Offline
What your asking for is a nondetermenistic evaluator. Do you have any idea how hard that is to for the scratch team to program?????
Offline
joefarebrother wrote:
What your asking for is a nondetermenistic evaluator. Do you have any idea how hard that is to for the scratch team to program?????
That's not non-deterministic. It basically does a "reverse distributive property" on the booleans. (Or something like that)
Offline
I'd like that.
Offline