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

#1 2012-07-03 11:23:49

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

Integer and string "or" block

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.


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

Offline

 

#2 2012-07-03 11:25:58

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

Re: Integer and string "or" block

What would it report? 6 or 7?

Last edited by SciTecCf (2012-07-03 11:26:23)


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

Offline

 

#3 2012-07-03 11:29:16

Wes64
Scratcher
Registered: 2011-08-19
Posts: 1000+

Re: Integer and string "or" block

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)


Experienced 2.0 Tester: Ask me questions!
Using Firefox 13.0, Flash plugin version 11.4.402.287, and Windows XP Professional.

Offline

 

#4 2012-07-03 11:36:01

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

Re: Integer and string "or" block

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.


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

Offline

 

#5 2012-07-03 11:50:45

Wes64
Scratcher
Registered: 2011-08-19
Posts: 1000+

Re: Integer and string "or" block

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.


Experienced 2.0 Tester: Ask me questions!
Using Firefox 13.0, Flash plugin version 11.4.402.287, and Windows XP Professional.

Offline

 

#6 2012-07-03 12:56:46

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: Integer and string "or" block

I disagree; it's like this in regular programming too and it's a good habit to get into.


Posts: 20000 - Show all posts

Offline

 

#7 2012-07-03 13:03:23

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Integer and string "or" block

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?  tongue

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

 

#8 2012-07-03 14:35:28

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

Re: Integer and string "or" block

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"

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.


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

Offline

 

#9 2012-07-03 14:48:00

Wes64
Scratcher
Registered: 2011-08-19
Posts: 1000+

Re: Integer and string "or" block

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.


Experienced 2.0 Tester: Ask me questions!
Using Firefox 13.0, Flash plugin version 11.4.402.287, and Windows XP Professional.

Offline

 

#10 2012-07-03 14:48:12

Molybdenum
Scratcher
Registered: 2012-06-17
Posts: 1000+

Re: Integer and string "or" block

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"

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.

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


"The Enrichment Center is required to remind you that you will be baked, and then there will be cake."
(|Balls and Platforms: Stay on!|) (|NaOS-H: An operating system... Or is it?|)

Offline

 

#11 2012-07-03 14:55:58

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Integer and string "or" block

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

 

#12 2012-07-03 17:14:44

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: Integer and string "or" block

What your asking for is a nondetermenistic evaluator. Do you have any idea how hard that is to for the scratch team to program?????


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#13 2012-07-03 17:26:29

Molybdenum
Scratcher
Registered: 2012-06-17
Posts: 1000+

Re: Integer and string "or" block

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)


"The Enrichment Center is required to remind you that you will be baked, and then there will be cake."
(|Balls and Platforms: Stay on!|) (|NaOS-H: An operating system... Or is it?|)

Offline

 

#14 2012-07-03 18:19:02

RedRocker227
Scratcher
Registered: 2011-10-26
Posts: 1000+

Re: Integer and string "or" block

I'd like that.


Why

Offline

 

Board footer