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

#1 2012-02-10 12:02:55

rabbit1131
Scratcher
Registered: 2009-10-16
Posts: 1000+

Costume selection with variables

Many topics are about how they set costumes to variables. So they'll make a script like the top script here

http://imgur.com/qCgHB


So it should switch to the costume with the name of the variable value right?
Wrong.
It will switch to the costume number. This can make things like health bars etc rather hard. So here is how to fix it (the bottom image):

http://imgur.com/qCgHB

This will turn the set of numbers into a string. So it will go the by the costume name, not number.

Hope this helps  smile


The Intergalactic Adventures of Revesilia! I hope you will partake in this gigantic undertaking, to build the sequel to the hit map The Adventures of Revesilia! The Intergalactic Adventures of Revesilia Map Builders Application thread! http://internetometer.com/image/35004.png

Offline

 

#2 2012-02-10 12:08:32

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

Re: Costume selection with variables

It always tries to go by the costume name first; it'll only go by the costume number if there isn't a costume with the same name as the variable.


Why

Offline

 

#3 2012-02-10 12:16:53

TargetheroTest
New Scratcher
Registered: 2012-02-04
Posts: 1

Re: Costume selection with variables

Both those scripts do the same thing. Joining a variable value with nothing isn't going to change it.

Offline

 

#4 2012-02-10 12:20:07

Targethero
Scratcher
Registered: 2008-09-08
Posts: 1000+

Re: Costume selection with variables

Oops, said that on the wrong account.


http://img97.imageshack.us/img97/3981/targethero2.png http://ls.gd/bo

Offline

 

#5 2012-02-10 13:28:52

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Costume selection with variables

TargetheroTest wrote:

Both those scripts do the same thing. Joining a variable value with nothing isn't going to change it.

Au contraire, joining the (x position) reporter, for example, with nothing like so:

set x to (10.1)
forever
set [xposition v] to (join (x position) [])
end
will cause the watcher for x position to show 10.1 and the watcher for the xposition variable to show 10.09999999999991.

Effectively, using a blanked join block stops Scratch rounding values, this can be very useful.

However, costumes will switch to the number if you ask it to switch to a number and to the name if you send it a string. This can be easily controlled by not using integers in costume names.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#6 2012-02-10 14:25:03

Targethero
Scratcher
Registered: 2008-09-08
Posts: 1000+

Re: Costume selection with variables

sparks wrote:

TargetheroTest wrote:

Both those scripts do the same thing. Joining a variable value with nothing isn't going to change it.

Au contraire, joining the (x position) reporter, for example, with nothing like so:

set x to (10.1)
forever
set [xposition v] to (join (x position) [])
end
will cause the watcher for x position to show 10.1 and the watcher for the xposition variable to show 10.09999999999991.

That wont have any effect on a variable(in place of the x reporter). They aren't auto-rounded, 10.1 will still be exactly 10.1, variables will always be exactly what you set them to, so using a blank join block wont change anything.

Last edited by Targethero (2012-02-10 16:06:24)


http://img97.imageshack.us/img97/3981/targethero2.png http://ls.gd/bo

Offline

 

#7 2012-02-10 16:18:03

rabbit1131
Scratcher
Registered: 2009-10-16
Posts: 1000+

Re: Costume selection with variables

TargetheroTest wrote:

Both those scripts do the same thing. Joining a variable value with nothing isn't going to change it.

Afraid I must disagree.
Joining a variable value with nothing will turn the input into a string. Using the string it will switch to the costume name. However if it's a number, it will switch to the costume number.


The Intergalactic Adventures of Revesilia! I hope you will partake in this gigantic undertaking, to build the sequel to the hit map The Adventures of Revesilia! The Intergalactic Adventures of Revesilia Map Builders Application thread! http://internetometer.com/image/35004.png

Offline

 

#8 2012-02-10 16:22:35

Targethero
Scratcher
Registered: 2008-09-08
Posts: 1000+

Re: Costume selection with variables

rabbit1131 wrote:

TargetheroTest wrote:

Both those scripts do the same thing. Joining a variable value with nothing isn't going to change it.

Afraid I must disagree.
Joining a variable value with nothing will turn the input into a string. Using the string it will switch to the costume name. However if it's a number, it will switch to the costume number.

Say I have a script like this:

when gf clicked
set [variable v] to (11)
switch to costume (variable)
If there is a costume named "11", it will switch to that costume, If you dont have a costume called "11" then it will switch to the eleventh costume. The same will happen with this script:

when gf clicked
set [variable v] to (11)
switch to costume (join (variable) [])

Last edited by Targethero (2012-02-10 16:56:48)


http://img97.imageshack.us/img97/3981/targethero2.png http://ls.gd/bo

Offline

 

#9 2012-02-10 16:57:36

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Costume selection with variables

Targethero wrote:

sparks wrote:

TargetheroTest wrote:

Both those scripts do the same thing. Joining a variable value with nothing isn't going to change it.

Au contraire, joining the (x position) reporter, for example, with nothing like so:

set x to (10.1)
forever
set [xposition v] to (join (x position) [])
end
will cause the watcher for x position to show 10.1 and the watcher for the xposition variable to show 10.09999999999991.

That wont have any effect on a variable(in place of the x reporter). They aren't auto-rounded, 10.1 will still be exactly 10.1, variables will always be exactly what you set them to, so using a blank join block wont change anything.

Build that script. The variable reporter shows 10.09999999999991. I didn't just make that up, I tested it first  tongue

To clear this up, I have created a project showing this download

this project has 11 costumes, costume 2 is named 11.

there are two block sets in the project.

 switch to costume ((11) + (0))
will switch to costume 11 whilst
 switch to costume (join [11] []) 
switches to costume 2

Last edited by sparks (2012-02-10 17:04:35)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#10 2012-02-10 17:14:46

Targethero
Scratcher
Registered: 2008-09-08
Posts: 1000+

Re: Costume selection with variables

sparks wrote:

Build that script. The variable reporter shows 10.09999999999991. I didn't just make that up, I tested it first  tongue

Im not saying the script you posted wont do as you say, I know it will, I've used that method many times lol. Im saying that if you do the same thing but with a variable instead of the x reporter, a variable wont change, you wont get an extended answer. Like this script:

set [variable2 v] to (10.1)
forever
set [variable1 v] to (join (variable 2) [])
end
The answer obviously wont change from 10.1

sparks wrote:

there are two block sets in the project.

 switch to costume ((11) + (0))
will switch to costume 11 whilst
 switch to costume (join [11] []) 
switches to costume 2

Yes but

switch to costume (join [11] [0])
will also switch to costume 11, and
switch to costume ((11)+())
will switch to costume 2.

Last edited by Targethero (2012-02-10 17:20:32)


http://img97.imageshack.us/img97/3981/targethero2.png http://ls.gd/bo

Offline

 

#11 2012-02-10 17:26:20

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Costume selection with variables

Oh I see what you're on about. I also just tried out the scripts in the first post and they are wrong as variables are strings to begin with. In fact, it switches to the name as default with a variable unless you put the variable in a (var) + ( )) situation, turning it into a number.

Last edited by sparks (2012-02-10 17:26:27)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#12 2012-02-10 17:49:49

Targethero
Scratcher
Registered: 2008-09-08
Posts: 1000+

Re: Costume selection with variables

sparks wrote:

Oh I see what you're on about. I also just tried out the scripts in the first post and they are wrong as variables are strings to begin with. In fact, it switches to the name as default with a variable unless you put the variable in a (var) + ( )) situation, turning it into a number.

Exactly.


http://img97.imageshack.us/img97/3981/targethero2.png http://ls.gd/bo

Offline

 

#13 2012-02-10 17:51:14

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Costume selection with variables

Targethero wrote:

Exactly.

tongue


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#14 2012-02-10 18:01:43

rabbit1131
Scratcher
Registered: 2009-10-16
Posts: 1000+

Re: Costume selection with variables

Actually, those are not the reults I was getting. I tried setting the variable, and it kept setting it sometimes to a number, sometimes to a string. I was not using any operators.


The Intergalactic Adventures of Revesilia! I hope you will partake in this gigantic undertaking, to build the sequel to the hit map The Adventures of Revesilia! The Intergalactic Adventures of Revesilia Map Builders Application thread! http://internetometer.com/image/35004.png

Offline

 

#15 2012-02-11 04:49:29

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

Re: Costume selection with variables

sparks wrote:

TargetheroTest wrote:

Both those scripts do the same thing. Joining a variable value with nothing isn't going to change it.

Au contraire, joining the (x position) reporter, for example, with nothing like so:

set x to (10.1)
forever
set [xposition v] to (join (x position) [])
end
will cause the watcher for x position to show 10.1 and the watcher for the xposition variable to show 10.09999999999991.

Effectively, using a blanked join block stops Scratch rounding values, this can be very useful.

This is because sometimes scratch cannot display a sprite at an exact position so it slightly alters the position but auto-rounds it for display (although retains the value for processing). Adding a space character to the number turns it into a string so it stops auto-rounding.


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-02-11 08:57:42

CheeseMunchy
Scratcher
Registered: 2008-10-13
Posts: 1000+

Re: Costume selection with variables

um I don't see how that'l do anything.


6418,

Offline

 

Board footer