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

#1 2011-12-18 21:45:01

WingsGames
Scratcher
Registered: 2011-02-21
Posts: 500+

"Make variable" block

I think that there should be a block that makes a new variable. That way, if you're, say, making a flashcard project, you'd be able to have as many as you want!


Are you an aspiring home decorator? If so, please answer my question!

Offline

 

#2 2011-12-18 21:54:52

PaperMario123
Scratcher
Registered: 2011-11-25
Posts: 500+

Re: "Make variable" block

And... how would it be used? I mean, you have to say the variable name, but, if it doesn't really exist until it's ran... well, you should understand. Plus, it would be hard to code in Squeak. And what if someone put this in a "forever" block? Lagging to the max.


http://i.picasion.com/pic46/52268c4a041cced4c8ed97cc7468f869.gif

Offline

 

#3 2011-12-19 03:52:10

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

Re: "Make variable" block

That can be done in Panther, but I agree it would be useful to have. Though as PaperMario123 said, it would cause extreme lag over time.


Why

Offline

 

#4 2011-12-19 14:12:17

WingsGames
Scratcher
Registered: 2011-02-21
Posts: 500+

Re: "Make variable" block

PaperMario123 wrote:

And... how would it be used? Well, it could be used to create a new document in a word processor, or it could be used to make flashcards or something. I mean, you have to say the variable name, but, if it doesn't really exist until it's ran... well, you should understand. You would be able to do this in the editor. You would right click on the variable block and it would say "name my copies...". There would be another variable created called "variable1 copies", which would allow you to program the copies. Plus, it would be hard to code in Squeak. I don't know enough about Squeak to give some workaround, but I'll take your word for it . And what if someone put this in a "forever" block? Lagging to the max. I agree, it would cause lagging, but no project should need an infinite number of variables.

Last edited by WingsGames (2011-12-19 14:13:16)


Are you an aspiring home decorator? If so, please answer my question!

Offline

 

#5 2011-12-20 17:34:51

SJRCS_011
Scratcher
Registered: 2011-02-07
Posts: 1000+

Re: "Make variable" block

WingsGames wrote:

PaperMario123 wrote:

And... how would it be used? Well, it could be used to create a new document in a word processor, or it could be used to make flashcards or something. I mean, you have to say the variable name, but, if it doesn't really exist until it's ran... well, you should understand. You would be able to do this in the editor. You would right click on the variable block and it would say "name my copies...". There would be another variable created called "variable1 copies", which would allow you to program the copies. Plus, it would be hard to code in Squeak. I don't know enough about Squeak to give some workaround, but I'll take your word for it . And what if someone put this in a "forever" block? Lagging to the max. I agree, it would cause lagging, but no project should need an infinite number of variables.

Also, if you were using a SmartPort system for mesh chat boxes ( a variable is created for each ip to transfer data [for my Panther projects]), you would want to be able to create/delete variables.  Maybe also a create list and delete list blocks.

Hehehe.  As for the squeak code, just ask the Panther devs.

Last edited by SJRCS_011 (2011-12-20 17:35:46)


http://i.imgur.com/vQqtH.png
Learning to Program in a Nutshell:  "You're missing a closing parentheses" - LS97

Offline

 

#6 2011-12-22 10:43:08

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

Re: "Make variable" block

If it was put in a c-block, it will automaticly be deleted at the end of the c-block so if put in a forever block it will be constantly be created and deleted. There would also be blocks (variable named [ ]) and |set variable named [ ] to [ ]|  so you can use theese variables. It is possible in squeak, it works in panther.


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

 

#7 2011-12-22 10:47:48

WingsGames
Scratcher
Registered: 2011-02-21
Posts: 500+

Re: "Make variable" block

joefarebrother wrote:

If it was put in a c-block, it will automaticly be deleted at the end of the c-block so if put in a forever block it will be constantly be created and deleted. There would also be blocks (variable named [ ]) and |set variable named [ ] to [ ]|  so you can use theese variables. It is possible in squeak, it works in panther.

So, that solves the lagging problem.


Are you an aspiring home decorator? If so, please answer my question!

Offline

 

#8 2011-12-23 17:22:43

WingsGames
Scratcher
Registered: 2011-02-21
Posts: 500+

Re: "Make variable" block

bump


Are you an aspiring home decorator? If so, please answer my question!

Offline

 

#9 2011-12-25 12:30:46

prokohtu
Scratcher
Registered: 2008-06-19
Posts: 100+

Re: "Make variable" block

but you can also use a list for that


Scratch's most realistic F1 simulator
https://lh6.googleusercontent.com/-qIdF-SzbTzw/UU29tK-FYvI/AAAAAAAAAOs/vRFKr1Iwldc/s225/logo.jpg

Offline

 

#10 2011-12-25 12:47:05

WingsGames
Scratcher
Registered: 2011-02-21
Posts: 500+

Re: "Make variable" block

prokohtu wrote:

but you can also use a list for that

How so?


Are you an aspiring home decorator? If so, please answer my question!

Offline

 

#11 2011-12-25 13:12:39

SJRCS_011
Scratcher
Registered: 2011-02-07
Posts: 1000+

Re: "Make variable" block

WingsGames wrote:

prokohtu wrote:

but you can also use a list for that

How so?

add _ to _
Basically, just using the list items as variables.
However, you wouldn't be able to use this for mesh.


http://i.imgur.com/vQqtH.png
Learning to Program in a Nutshell:  "You're missing a closing parentheses" - LS97

Offline

 

#12 2011-12-28 10:28:26

johnaveryhanson
Scratcher
Registered: 2011-12-22
Posts: 58

Re: "Make variable" block

if you just do this it would work[blocks]                     http://scratch.mit.edu/forums/viewtopic.php?id=84017#req_message     
http://scratch.mit.edu/forums/viewtopic.php?id=84017#req_messagehttp://scratch.mit.edu/forums/viewtopic.php?id=84017#req_message
http://scratch.mit.edu/forums/viewtopic.php?id=84017#req_message
                                                [/blocks]


i am currently http://blocks.scratchr.org/API.php?user=johnaveryhanson&action=onlineStatus&type=text

Offline

 

#13 2012-08-11 20:30:01

MountainBoy
Scratcher
Registered: 2010-07-25
Posts: 34

Re: "Make variable" block

what you could do to solve the lag is, to have sqeuck do a counter (ctr) variable that counts how many times a variable is made using the block, and once more than ___ amount is made it stops and highlights the block red, like if you were to do:


when gf forever if <(0 / 0)>

end

Offline

 

#14 2012-08-12 02:47:30

soniku3
Scratcher
Registered: 2011-12-08
Posts: 1000+

Re: "Make variable" block

MountainBoy wrote:

what you could do to solve the lag is, to have sqeuck do a counter (ctr) variable that counts how many times a variable is made using the block, and once more than ___ amount is made it stops and highlights the block red, like if you were to do:


when gf clicked 
<forever if <(0 / 0)>

end

Last edited by soniku3 (2012-08-12 02:48:24)


internet's all about cats today.

Offline

 

#15 2012-08-12 13:13:53

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

Re: "Make variable" block

MountainBoy wrote:

what you could do to solve the lag is, to have sqeuck do a counter (ctr) variable that counts how many times a variable is made using the block, and once more than ___ amount is made it stops and highlights the block red, like if you were to do:


when gf forever if <(0 / 0)>

end

Necropost...

Besides, you can use lists


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

 

#16 2012-11-26 15:19:52

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: "Make variable" block

Support.  This isn't a necropost, as I was going to suggest it, but I searched.
Lists won't work, as you would need to know exactly what position in the list each "variable" were in.


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#17 2012-11-28 16:18:23

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

Re: "Make variable" block

One list called vars and another called vals.

when i receive [setvar v]
set [index v] to (0)
repeat (length of [vars v])
 change [index v] by (1)
 if <(item (index) of [vars v]) = (variable)>
  replace item (index) of [vals v] with (value)
  stop script
 end
end
add (variable) to [vars v]
add (value) to [vals v]

when i receive [getvar v]
set [index v] to (0)
repeat (length of [vars v])
 change [index v] by (1)
 if <(item (index) of [vars v]) = (variable)>
  set [value v] to (item (index) of [vals v])
  stop script
 end
end
add (variable) to [vars v]
add [0] to [vals v] //or any default value
set [value v] to [0] 
And that's how you work around it with lists  smile


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

 

#18 2012-11-29 12:14:42

firedrake969_test
Scratcher
Registered: 2012-08-08
Posts: 500+

Re: "Make variable" block

joefarebrother wrote:

One list called vars and another called vals.

when i receive [setvar v]
set [index v] to (0)
repeat (length of [vars v])
 change [index v] by (1)
 if <(item (index) of [vars v]) = (variable)>
  replace item (index) of [vals v] with (value)
  stop script
 end
end
add (variable) to [vars v]
add (value) to [vals v]

when i receive [getvar v]
set [index v] to (0)
repeat (length of [vars v])
 change [index v] by (1)
 if <(item (index) of [vars v]) = (variable)>
  set [value v] to (item (index) of [vals v])
  stop script
 end
end
add (variable) to [vars v]
add [0] to [vals v] //or any default value
set [value v] to [0] 
And that's how you work around it with lists  smile

How many Scratchers know how to use that?  How many people use lists?  What if you need to make a variable but later replace it?   sad


Alt of Firedrake969.

Offline

 

#19 2012-11-29 23:08:23

TorbyFork234
Scratcher
Registered: 2012-03-01
Posts: 1000+

Re: "Make variable" block

firedrake969_test wrote:

joefarebrother wrote:

One list called vars and another called vals.

when i receive [setvar v]
set [index v] to (0)
repeat (length of [vars v])
 change [index v] by (1)
 if <(item (index) of [vars v]) = (variable)>
  replace item (index) of [vals v] with (value)
  stop script
 end
end
add (variable) to [vars v]
add (value) to [vals v]

when i receive [getvar v]
set [index v] to (0)
repeat (length of [vars v])
 change [index v] by (1)
 if <(item (index) of [vars v]) = (variable)>
  set [value v] to (item (index) of [vals v])
  stop script
 end
end
add (variable) to [vars v]
add [0] to [vals v] //or any default value
set [value v] to [0] 
And that's how you work around it with lists  smile

How many Scratchers know how to use that?  How many people use lists?  What if you need to make a variable but later replace it?   sad

You would just iterate through the "var" list, finding the name, and then use whatever item # it's at to replace the value in the "val" list to whatever you want.

when gf clicked
set [variable v] to [variable name]
set [value v] to [whatever value you want it to change to]
broadcast [changevar v]

when i receive [changevar v]
set [index v] to (0)
repeat (length of [vars v])
 change [index v] by (1)
 if <(item (index) of [vars v]) = (variable)> 
  replace item (index) of [vals v] with (value)
  stop script
 end
end

Offline

 

#20 2012-11-29 23:24:49

kayybee
Scratcher
Registered: 2009-12-07
Posts: 1000+

Re: "Make variable" block

I'm not sure if the above script works, but if it does then use it.

The point is that there are a lot of things that you can actually do (even with lists, even if you don't like to use them) with the current blocks (or ones in 2.0) and if you don't go finding these workarounds, you won't be learning as much as you could.

Offline

 

Board footer