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

#1 2012-12-06 23:45:30

BurritoSM
Scratcher
Registered: 2012-11-11
Posts: 33

Variable creation in-project?

I have a new idea; in-project coding.

As in, you type stuff in and design stuff, and it interacts.

my big problem is that variables would be a key in this creation, and I don't know of any way to be able for a user to create variables and name them what the want to name them.

Is there any possible way to do this without lists?  If there isn't, than could lists work, and how?

Offline

 

#2 2012-12-07 00:06:52

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Variable creation in-project?

BurritoSM wrote:

I have a new idea; in-project coding.

As in, you type stuff in and design stuff, and it interacts.

my big problem is that variables would be a key in this creation, and I don't know of any way to be able for a user to create variables and name them what the want to name them.

Is there any possible way to do this without lists?  If there isn't, than could lists work, and how?

A very simple method using lists does exist. I am not familiar with any methods that could work without them.

Basically:
Create two lists: Name and Value
when the user creates a new "variable," the name is added to the list and a value is added to the value column.  You can then recall variables by having the user reference the name or number of the variable and using a repeat block to scan the list of names then simply using that value to recall the variable's value...if that makes sense.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#3 2012-12-07 20:07:16

BurritoSM
Scratcher
Registered: 2012-11-11
Posts: 33

Re: Variable creation in-project?

How would I use the blocks to find each specific variable?

I am not very good with lists.

Offline

 

#4 2012-12-09 01:37:45

BurritoSM
Scratcher
Registered: 2012-11-11
Posts: 33

Re: Variable creation in-project?

Bumping, as i see I haven't received a reply yet.

Offline

 

#5 2012-12-09 02:00:13

JH1010
Scratcher
Registered: 2012-05-31
Posts: 1000+

Re: Variable creation in-project?

The only way is to use lists.

Offline

 

#6 2012-12-09 08:57:59

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Variable creation in-project?

set [name v] to [apple]
set [i v] to (1)
repeat until<(item (i) of [variable names v]) = (name)>
change [i v] by (1)
end
say (item (i) of [values v])


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#7 2012-12-09 08:59:32

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Variable creation in-project?

Essentially, keep the values and names of corresponding variables at the same spot on lists, so that "item 1" on both lists both belong to the first variable created, "item 2' on both lists both belong to the second variable created, etc.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#8 2012-12-09 13:31:06

BurritoSM
Scratcher
Registered: 2012-11-11
Posts: 33

Re: Variable creation in-project?

Okay, but, how can I locate each one?

Offline

 

#9 2012-12-09 13:56:39

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Variable creation in-project?

You locate it by using the script above.

Set "name" in the script above to the variable you want to read.

To set the value of a variable:

set [name v] to [name of var to set]
set [value v] to [value you want to set it to]
set [i v] to (0)
repeat until<(item (i) of [names v]) = (name)>
change [i v] by (1)
end
replace item (i) of [values v] with (value)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#10 2012-12-09 15:21:33

BurritoSM
Scratcher
Registered: 2012-11-11
Posts: 33

Re: Variable creation in-project?

Thank you.

Offline

 

#11 2012-12-10 18:40:38

rickvh
New Scratcher
Registered: 2012-12-10
Posts: 21

Re: Variable creation in-project?

When I broadcast a variable name does the value broadcast with it? I am assuming so but my script doesn't doesn't behave like it. I initially created a variable called sound exist  then set sound exist = 0 in the script of one sprite. Then when sprite one does it's thing I broadcast sound exist. Then play sound until done and then change sound exist by one.
    In sprite two I created an if else statement: if: sound exist = 0 a forever loop is started, else: sprite two goes to a location and stays there. The problem is: even though the script for sprite one set the variable to 0 It doesn't seem to be evaluated by the if-else statement in sprite two and it bypasses the whole block.
    Also, is the broadcast continuous or must you rebroadcast every time a value changes?

Offline

 

Board footer