On the block
| v| sensor value
the dropdown list code is:
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]]].
^ t1I modded this to:
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].
^ t1This 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!
Offline
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.
Offline
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
Offline
so do you have a problem with the first bit or the second bit of code?
Offline
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!
Offline
Here I improved the 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].
^ t1Offline
i think the problem you have is at the index etc bit of 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
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
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?
Offline
ok. i'll try to remake it!
Offline
oh, one last thing, why would you need this?
Offline
Im making list sharing over mesh on my mod. Im storing the lists in variables and then transmitting them!
Offline
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