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

#1 2011-07-29 16:10:31

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Why won't this block work?

Code:

FontExists: t1 
    | t2 |
    t2 _ UnicodePlugin getFontList.
    (t2 includes: t1)
        ifTrue: [^ true].
    ^ false

(t1 is a String argument.)

Basically what this code does is call getFontList to t2, making t2 an array containing string names of every font on the computer.  Then, if t1 is part of that array, it reports true.  Otherwise, false.

The Problem:

It will always return false.  And, interestingly, if you replace the t1 in (t2 includes: t1) with 'Arial', it works.  Same if put this in the code part in the workspace, define t1 as a temporary variable instead, and set it to 'Arial'.  But as it is above, it doesn't work.

I tested this extensively and can't figure it out.  If someone can fix this block, I'll share it at the Block Library with credit to me as creator and credit to whoever discovered the solution as an improvement.  Please help!

Offline

 

#2 2011-07-29 17:33:50

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Why won't this block work?

Please, I could really use the help!

Offline

 

#3 2011-07-29 17:37:54

scratcher7_13
Scratcher
Registered: 2011-02-09
Posts: 1000+

Re: Why won't this block work?

I think it has to do with whether t1 is being recognized as a string or not.


♫ 90% of teens can't do math. If you are one of the 40% of teens who can, copy and paste this into your signature. ♫♪
http://dl.dropbox.com/u/6273449/BlockLibraryTitle.pnghttp://i.imgur.com/mr9Hf.gif

Offline

 

#4 2011-07-29 17:46:35

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Why won't this block work?

scratcher7_13 wrote:

I think it has to do with whether t1 is being recognized as a string or not.

I already tried that.  Originally it was (t2 includes: t1 asString) and it still glitched.

Offline

 

#5 2011-07-29 18:46:27

Baderous
New Scratcher
Registered: 2011-04-14
Posts: 100+

Re: Why won't this block work?

Convert the strings of fonts to UFT8 strings, since the input will be a UTF8 string too, then make the comparison:

Code:

fontExists: t1

    | t2 |
    t2 _ UnicodePlugin getFontList collect: [:f | f asUTF8].
    ^ (t2 includes: t1)

Offline

 

#6 2011-07-29 19:11:18

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Why won't this block work?

Baderous wrote:

Convert the strings of fonts to UFT8 strings, since the input will be a UTF8 string too, then make the comparison:

Code:

fontExists: t1

    | t2 |
    t2 _ UnicodePlugin getFontList collect: [:f | f asUTF8].
    ^ (t2 includes: t1)

OK, but I'm away from home and using a 3DS.  I'll test it if I can tonight, though maybe tomorrow.

I did try UTF8, but I was trying to convert t1 to UTF8.

Assuming this works, thanks so much!

Offline

 

#7 2011-07-29 19:14:21

Baderous
New Scratcher
Registered: 2011-04-14
Posts: 100+

Re: Why won't this block work?

This works, I tested it.

Offline

 

#8 2011-07-29 19:24:06

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Why won't this block work?

Baderous wrote:

This works, I tested it.

Oh.  Thanks so much again!!!

Offline

 

#9 2011-08-23 15:23:56

didjexpert
Scratcher
Registered: 2011-05-09
Posts: 23

Re: Why won't this block work?

OK, but I'm away from home and using a 3DS.

3DS HAS INTERNET!?!?  yikes
I HAVE GOTTA GET ONE!!!!!  big_smile


http://lunibook.com/signatures/Overbuild/maelstromFighterDeluxe/assembly.png

Offline

 

Board footer