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

#1 2010-07-31 08:13:04

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

A little help

On the block
|   v| sensor value
the dropdown list code is:

Code:

hookupSensorNames
    | t1 t2 t3 |
    t1 _ #('slider' 'light' 'sound' 'resistance' ).
    t1 _ t1 , #('-' 'tilt' 'distance' ).
    (t2 _ self ownerThatIsA: ScratchStageMorph) ifNotNil: [t2 scratchServer
            ifNotNil: 
                [t3 _ t2 scratchServer sensorNames.
                t3 size > 0 ifTrue: [^ t1 , {'-'} , t2 scratchServer sensorNames]]].
    ^ t1

I modded this to:

Code:

hookupSensorNames
    | t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 |
t9_ 'lists'.
    t1 _ #('slider' 'light' 'sound' 'resistance' ).
    t1 _ t1 , #('-' 'tilt' 'distance' ).
    (t2 _ self ownerThatIsA: ScratchStageMorph) ifNotNil: [t2 scratchServer
            ifNotNil: 
                [t3 _ t2 scratchServer sensorNames.
                t3 size > 0
                    ifTrue: 
                        [t1 _ t1 , #('-' ).
                        t1 _ t1 , t2 scratchServer sensorNames]]].
    t4 _ self
                indexOf: t9
                startingAt: 0
                in: t1.
    t4 _ t4 asNumber.
    t4 = 0
        ifFalse: 
            [t4 _ t4 - 2.
            t7 _ 0.
            t10 _ ''.
            t4
                timesRepeat: 
                    [t7 _ t7 + 1.
                    t6 _ self letter: t7 of: t1.
                    t10 _ self concatenate: t10 with: t6].
            t5 _ self stringLength: t1.
            t4 _ t4 + 7.
            t7 _ t5 - t4.
            t8 _ ''.
            t7
                timesRepeat: 
                    [t4 _ t4 + 1.
                    t6 _ self letter: t4 of: t1.
                    t8 _ self concatenate: t8 with: t6].
            t1 _ self concatenate: t10 with: t8].

    ^ t1

This will remove the chosen phrase (lists) from the dropdown list, it has a custom meathod (index of %s starting at %n in $s) which works, and so does this.

if you make a block:
('sensors' #r #hookupSensorNames)

its reports:

( 'slider' 'cheese' ... )
but when I put it in a
(|   v| sensor value)
block it causes a error.

WHY!


You can now reach me on Twitter @johnnydean1_

Offline

 

#2 2010-08-01 15:31:31

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: A little help

bump


You can now reach me on Twitter @johnnydean1_

Offline

 

#3 2010-08-01 15:35:34

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: A little help

Wrong string class? (IDK, just a guess)


nXIII

Offline

 

#4 2010-08-01 15:38:37

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: A little help

well it pops up with a error, can you make a better code. It is designed to eliminate the word lists off of the sensor value dropdown.


You can now reach me on Twitter @johnnydean1_

Offline

 

#5 2010-08-01 15:55:41

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: A little help

Wrong class. You're trying to use an Array as a UTF8


nXIII

Offline

 

#6 2010-08-01 17:35:03

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: A little help

How can I change it?


You can now reach me on Twitter @johnnydean1_

Offline

 

#7 2010-08-02 11:43:41

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: A little help

bump


You can now reach me on Twitter @johnnydean1_

Offline

 

#8 2010-08-02 16:15:07

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: A little help

bump


You can now reach me on Twitter @johnnydean1_

Offline

 

#9 2010-08-02 17:47:21

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: A little help

... a type cast?


nXIII

Offline

 

#10 2010-08-03 03:47:36

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: A little help

how like
asUTF8


You can now reach me on Twitter @johnnydean1_

Offline

 

#11 2010-08-03 18:19:33

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: A little help

asString = as: String
storeString = code to store the object
printString = string to print (i.e. show in Transcript)
asUTF8 = as a UTF8 string (may only work with strings, I forget)
asUTF32 = same as above with a UTF32 string


nXIII

Offline

 

#12 2010-08-04 04:18:49

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: A little help

Still not working.


You can now reach me on Twitter @johnnydean1_

Offline

 

#13 2010-08-04 11:17:54

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

Re: A little help

so do you have a problem with the first bit or the second bit of code?

Offline

 

#14 2010-08-04 11:20:48

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: A little help

2nd bit its the wrong type as nXIII said but I can't work out how to change it as  the thing he gave me doesnt work!


You can now reach me on Twitter @johnnydean1_

Offline

 

#15 2010-08-04 11:23:27

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: A little help

Here I improved the code:

Code:

hookupsensornames

    | t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11|
t9_ 'lists'.
t11_ self stringLength: (t9). 
    t1 _ #('slider' 'light' 'sound' 'resistance' ).
    t1 _ t1 , #('-' 'tilt' 'distance' ).
    (t2 _ self ownerThatIsA: ScratchStageMorph) ifNotNil: [t2 scratchServer
            ifNotNil: 
                [t3 _ t2 scratchServer sensorNames.
                t3 size > 0
                    ifTrue: 
                        [t1 _ t1 , #('-' ).
                        t1 _ t1 , t2 scratchServer sensorNames]]].
    t4 _ self
                indexOf: t9
                startingAt: 0
                in: t1.
    t4 _ t4 asNumber.
    t4 = 0
        ifFalse: 
            [t4 _ t4 - 2.
            t7 _ 0.
            t10 _ ''.
t4_ t4 - 1.
            t4
                timesRepeat: 
                    [t7 _ t7 + 1.
                    t6 _ self letter: t7 of: t1.
                    t10 _ self concatenate: t10 with: t6].
t4_ t4 + 1.
            t5 _ self stringLength: t1.
            t4 _ t4 + 7.
            t7 _ t5 - t11.
t7_ t7 + 2.
            t8 _ ''.
            t7
                timesRepeat: 
                    [t4 _ t4 + 1.
                    t6 _ self letter: t4 of: t1.
                    t8 _ self concatenate: t8 with: t6].
            t1 _ self concatenate: t10 with: t8].

    ^ t1

You can now reach me on Twitter @johnnydean1_

Offline

 

#16 2010-08-04 11:23:45

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

Re: A little help

i think the problem you have is at the index etc bit of code.

Code:

   t4 _ self
                indexOf: t9
                startingAt: 0
                in: t1.

since t1 is an array and not a string it gets an error.

am i correct?

Offline

 

#17 2010-08-04 11:25:30

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

Re: A little help

if i'm not please post a very detailed explanation of what you want the code to do and i'll re-write it all for you.

Offline

 

#18 2010-08-04 11:31:04

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: A little help

I have added the index of into my mod.

Here goes:
On the (|slider v| sensor value) block I want to alter the dropdown list.
I need a piece of code to exclude any value from the dropdown e.g
Slider
light
sound

I could ask the code to get rid of sound from the list. But heres the clever bit, I need it to also to be able to remove mesh variables of my choosing. So get it?


You can now reach me on Twitter @johnnydean1_

Offline

 

#19 2010-08-04 11:32:12

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: A little help

Oh and no thats not the problem!


You can now reach me on Twitter @johnnydean1_

Offline

 

#20 2010-08-04 11:33:15

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

Re: A little help

ok. i'll try to remake it!

Offline

 

#21 2010-08-04 11:35:54

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: A little help

thanks!


You can now reach me on Twitter @johnnydean1_

Offline

 

#22 2010-08-04 11:39:30

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

Re: A little help

oh, one last thing, why would you need this?

Offline

 

#23 2010-08-04 11:41:56

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: A little help

Im making list sharing over mesh on my mod. Im storing the lists in variables and then transmitting them!


You can now reach me on Twitter @johnnydean1_

Offline

 

#24 2010-08-04 11:46:19

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

Re: A little help

alright. i'm not sure if this is what you were looking for, but i figured it out.

hookupSensorNames
    | t1 t2 t3 t4 |
    t1 _ #('slider' 'light' 'sound' 'resistance' ).
    t1 _ t1 , #('-' 'tilt' 'distance' ).
    (t2 _ self ownerThatIsA: ScratchStageMorph) ifNotNil: [t2 scratchServer
            ifNotNil:
                [t3 _ t2 scratchServer sensorNames.
                t3 size > 0 ifTrue: [^ t1 , {'-'} , t2 scratchServer sensorNames]]].
    t4 _ 1.
    t1 size
        timesRepeat:
            [(t1 at: t4)
                = 'distance' ifTrue: [t1 at: t4 put: '-'].
            t4 _ t4 + 1].
    ^ t1

this code takes away the distance bit from the menu. you can change it to whatever you want to exclude. i haven't tried it with mesh though...

Offline

 

#25 2010-08-04 11:51:05

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: A little help

It works thanks!


You can now reach me on Twitter @johnnydean1_

Offline

 

Board footer