The next post contains some useful blocks!
Offline
Name:
Place of $String$ in $List$
Type:
-r
Code:
|t3 t4 t5 t6|
t3_ 0.
t4_ 0.
t5_ self lineCountOfList: (t2).
t6_ ''.
t5 timesRepeat: [
t3_ t3 + 1.
t4_ self getLine: (t3) ofList: (t2).
t4 = t1
ifTrue: [
t6_ t3.
].
].
t6 = ''
ifTrue: [
^ 0.
]
ifFalse:[
^t6.
].
-------------------
Name:
Complile $List$ with $String$ as breaker
Type:
-r
Code:
|t3 t4 t5 t6|
t3_ self lineCountOfList: (t1).
t4_ '' .
t6_ 0.
t3 timesRepeat:[
t6_ t6 + 1.
t5_ self getLine: (t6) ofList: (t1) .
t5_ self concatenate: (t5) with: (t2).
t4_ self concatenate: (t4) with: (t5).
].
^t4
------------------
Name:
Decompile $String$ to $List$ with $String$ as breaker
Type:
-
Code:
|t4 t5 t6 t7 t8 t9|
t4_ self stringLength: (t1).
t5_ self letter: (t4) of: (t1).
t5 = t3
ifTrue: [ t9_ t1.]
ifFalse: [
t9_ self concatenate: (t1) with: (t3)].
t4_0.
t5_0.
t6_ ''.
t8_ self stringLength: (t9) .
t8 timesRepeat:[
t4_ t4 + 1.
t5_ self letter: (t4) of: (t9).
t5 = t3
ifTrue:[
self append: (t6) toList: (t2).
t6_ ''.
]
ifFalse:[
t6_ self concatenate: (t6) with: (t5).
].
].
----------------------
Name:
$String$ in dialog confirmed?
Type:
-r
Code:
^ DialogBoxMorph ask: t1
------------------
Name:
ask in dialog $String$
Type:
-r
Code:
ScratchPrompterMorph lastAnswer: (StringDialog ask: t1).
^ self answer
-----------------------
Name: (Binary to hexamadecimal colour)
Binary: $String$ to colour
Type:
-r
Code:
|length n1 n2 n3 n4 n5 n6 num x1 c1 input|
input_ t1.
input_ input asString.
n1_ 0000.
n2_ 0000.
n3_ 0000.
n4_ 0000.
n5_ 0000.
n6_ 0000.
length_ self stringLength: (input).
length > 23
ifTrue: [
n1_ self letters: (21) through: (24) of: (input).
n1_ n1 asNumber.
].
length > 19
ifTrue: [
n2_ self letters: (17) through: (20) of: (input).
n2_ n2 asNumber.
].
length > 15
ifTrue: [
n3_ self letters: (13) through: (16) of: (input).
n3_ n3 asNumber.
].
length > 11
ifTrue: [
n4_ self letters: (9) through: (12) of: (input).
n4_ n4 asNumber.
].
length > 7
ifTrue: [
n5_ self letters: (5) through: (8) of: (input).
n5_ n5 asNumber.
].
length > 3
ifTrue: [
n6_ self letters: (1) through: (4) of: (input).
n6_ n6 asNumber.
].
c1_ n1.
c1 = 0000
ifTrue: [
x1_ 0.
].
c1 = 0001
ifTrue: [
x1_ 1.
].
c1 = 0010
ifTrue: [
x1_ 2.
].
c1 = 0011
ifTrue: [
x1_ 3.
].
c1 = 0100
ifTrue: [
x1_ 4.
].
c1 = 0101
ifTrue: [
x1_ 5.
].
c1 = 0110
ifTrue: [
x1_ 6.
].
c1 = 0111
ifTrue: [
x1_ 7.
].
c1 = 1000
ifTrue: [
x1_ 8.
].
c1 = 1001
ifTrue: [
x1_ 9.
].
c1 = 1010
ifTrue: [
x1_ 'A'.
].
c1 = 1011
ifTrue: [
x1_ 'B'.
].
c1 = 1100
ifTrue: [
x1_ 'C'.
].
c1 = 1101
ifTrue: [
x1_ 'D'.
].
c1 = 1110
ifTrue: [
x1_ 'E'.
].
c1 = 1111
ifTrue: [
x1_ 'F'.
].
n1_ x1.
c1_ n2.
c1 = 0000
ifTrue: [
x1_ 0.
].
c1 = 0001
ifTrue: [
x1_ 1.
].
c1 = 0010
ifTrue: [
x1_ 2.
].
c1 = 0011
ifTrue: [
x1_ 3.
].
c1 = 0100
ifTrue: [
x1_ 4.
].
c1 = 0101
ifTrue: [
x1_ 5.
].
c1 = 0110
ifTrue: [
x1_ 6.
].
c1 = 0111
ifTrue: [
x1_ 7.
].
c1 = 1000
ifTrue: [
x1_ 8.
].
c1 = 1001
ifTrue: [
x1_ 9.
].
c1 = 1010
ifTrue: [
x1_ 'A'.
].
c1 = 1011
ifTrue: [
x1_ 'B'.
].
c1 = 1100
ifTrue: [
x1_ 'C'.
].
c1 = 1101
ifTrue: [
x1_ 'D'.
].
c1 = 1110
ifTrue: [
x1_ 'E'.
].
c1 = 1111
ifTrue: [
x1_ 'F'.
].
n2_ x1.
c1_ n3.
c1 = 0000
ifTrue: [
x1_ 0.
].
c1 = 0001
ifTrue: [
x1_ 1.
].
c1 = 0010
ifTrue: [
x1_ 2.
].
c1 = 0011
ifTrue: [
x1_ 3.
].
c1 = 0100
ifTrue: [
x1_ 4.
].
c1 = 0101
ifTrue: [
x1_ 5.
].
c1 = 0110
ifTrue: [
x1_ 6.
].
c1 = 0111
ifTrue: [
x1_ 7.
].
c1 = 1000
ifTrue: [
x1_ 8.
].
c1 = 1001
ifTrue: [
x1_ 9.
].
c1 = 1010
ifTrue: [
x1_ 'A'.
].
c1 = 1011
ifTrue: [
x1_ 'B'.
].
c1 = 1100
ifTrue: [
x1_ 'C'.
].
c1 = 1101
ifTrue: [
x1_ 'D'.
].
c1 = 1110
ifTrue: [
x1_ 'E'.
].
c1 = 1111
ifTrue: [
x1_ 'F'.
].
n3_ x1.
c1_ n4.
c1 = 0000
ifTrue: [
x1_ 0.
].
c1 = 0001
ifTrue: [
x1_ 1.
].
c1 = 0010
ifTrue: [
x1_ 2.
].
c1 = 0011
ifTrue: [
x1_ 3.
].
c1 = 0100
ifTrue: [
x1_ 4.
].
c1 = 0101
ifTrue: [
x1_ 5.
].
c1 = 0110
ifTrue: [
x1_ 6.
].
c1 = 0111
ifTrue: [
x1_ 7.
].
c1 = 1000
ifTrue: [
x1_ 8.
].
c1 = 1001
ifTrue: [
x1_ 9.
].
c1 = 1010
ifTrue: [
x1_ 'A'.
].
c1 = 1011
ifTrue: [
x1_ 'B'.
].
c1 = 1100
ifTrue: [
x1_ 'C'.
].
c1 = 1101
ifTrue: [
x1_ 'D'.
].
c1 = 1110
ifTrue: [
x1_ 'E'.
].
c1 = 1111
ifTrue: [
x1_ 'F'.
].
n4_ x1.
c1_ n5.
c1 = 0000
ifTrue: [
x1_ 0.
].
c1 = 0001
ifTrue: [
x1_ 1.
].
c1 = 0010
ifTrue: [
x1_ 2.
].
c1 = 0011
ifTrue: [
x1_ 3.
].
c1 = 0100
ifTrue: [
x1_ 4.
].
c1 = 0101
ifTrue: [
x1_ 5.
].
c1 = 0110
ifTrue: [
x1_ 6.
].
c1 = 0111
ifTrue: [
x1_ 7.
].
c1 = 1000
ifTrue: [
x1_ 8.
].
c1 = 1001
ifTrue: [
x1_ 9.
].
c1 = 1010
ifTrue: [
x1_ 'A'.
].
c1 = 1011
ifTrue: [
x1_ 'B'.
].
c1 = 1100
ifTrue: [
x1_ 'C'.
].
c1 = 1101
ifTrue: [
x1_ 'D'.
].
c1 = 1110
ifTrue: [
x1_ 'E'.
].
c1 = 1111
ifTrue: [
x1_ 'F'.
].
n5_ x1.
c1_ n6.
c1 = 0000
ifTrue: [
x1_ 0.
].
c1 = 0001
ifTrue: [
x1_ 1.
].
c1 = 0010
ifTrue: [
x1_ 2.
].
c1 = 0011
ifTrue: [
x1_ 3.
].
c1 = 0100
ifTrue: [
x1_ 4.
].
c1 = 0101
ifTrue: [
x1_ 5.
].
c1 = 0110
ifTrue: [
x1_ 6.
].
c1 = 0111
ifTrue: [
x1_ 7.
].
c1 = 1000
ifTrue: [
x1_ 8.
].
c1 = 1001
ifTrue: [
x1_ 9.
].
c1 = 1010
ifTrue: [
x1_ 'A'.
].
c1 = 1011
ifTrue: [
x1_ 'B'.
].
c1 = 1100
ifTrue: [
x1_ 'C'.
].
c1 = 1101
ifTrue: [
x1_ 'D'.
].
c1 = 1110
ifTrue: [
x1_ 'E'.
].
c1 = 1111
ifTrue: [
x1_ 'F'.
].
n6_ x1.
num_ '#'.
num_ self concatenate: (num) with: (n1).
num_ self concatenate: (num) with: (n2).
num_ self concatenate: (num) with: (n3).
num_ self concatenate: (num) with: (n4).
num_ self concatenate: (num) with: (n5).
num_ self concatenate: (num) with: (n6).
^ num
-------------------
IP $String$ is hosting mesh?
Type: b
Code:
| var1 sFrame server inmesh time timers |
self leaveMesh.
time_ self timer.
var1_ self stringLength: (t1).
var1 > 10
ifTrue: [
self joinMesh: (t1).
(sFrame _ self ownerThatIsA: ScratchFrameMorph) ifNil: [sFrame _ (self ownerThatIsA: OffscreenWorldMorph) frame].
(server _ sFrame workPane scratchServer) ifNil: [inmesh_ false.].
inmesh_ server.
var1_ false.
inmesh = false
ifFalse: [
var1_ true.
].
self leaveMesh.
timers_ self timer.
time_ timers - time.
time < 0.5
ifTrue: [
^ var1.
]
ifFalse: [
^ false.
].
]
ifFalse: [
^ false.
].
=============
File $String$ exists?
Type:
b
Code:
|contents exists other writing temp var dest|
dest_ t1.
writing_ 'I exist'.
contents_ self readFile: (dest).
self writeText: (writing) toFile: (dest).
other_ self readFile: (dest).
temp_ self stringLength: (writing).
var_ self stringLength: (other).
temp_ var - temp.
temp_ temp + 1.
temp_ self letters: (temp) through: (var) of: (other).
temp = writing
ifTrue: [
exists_ true.
self clearFile: (dest).
self writeText: (contents) toFile: (dest).
]
ifFalse: [
exists_ false.
].
^ exists
================
layer
type: r
code:
|layer|
layer_ owner submorphs indexOf: self.
layer = 1
ifFalse: [
layer_ layer - 1.
].
^ layer
==================
Ratio of $Number$ : $Number$
Type: r
Code:
| hcm highest number r1 r2 correct o1 o2 output breaker |
" The thing between the numbers "
breaker_ ':'.
highest_ t2.
t1 > t2
ifTrue: [
highest_ t1.
].
highest_ highest + 1.
number_ 0.
highest timesRepeat: [
correct_ 0.
correct_ correct asNumber.
number_ number + 1.
r1_ t1 \\ number.
r2_ t2 \\ number.
r1 = 0
ifTrue: [
correct_ correct + 1.
].
r2 = 0
ifTrue: [
correct_ correct + 1.
].
correct = 2
ifTrue: [
hcm_ number
].
].
o1_ t1 / hcm.
o2_ t2 / hcm.
output_ self concatenate: (o1) with: (' ').
output_ self concatenate: (output) with: (breaker).
output_ self concatenate: (output) with: (' ').
output_ self concatenate: (output) with: (o2).
^ output
Offline
I think it's better to use the [code] tag...
Offline
I think nXIII is going to do some MEGA optimization on those
Offline
for the hexadecimal one, why would you have colors in binary format?
Offline
LS97 wrote:
for the hexadecimal one, why would you have colors in binary format?
I don't know, I just know somone requested it!
Offline
im clicked?
Type: b
Code:
|clicked other stage|
clicked_ 0.
stage _ self ownerThatIsA: ScratchStageMorph.
other_ self containsPoint: stage adjustedCursorPoint.
other = true
ifTrue:
[
clicked_ clicked + 1.
].
other_ self mousePressed.
other = true
ifTrue:
[
clicked_ clicked + 1.
].
clicked = 2
ifTrue:
[
^ true.
]
ifFalse: [
^ false.
].
Offline
That is screaming nXIII optimise me, please.
Offline
johnnydean1 wrote:
LS97 wrote:
for the hexadecimal one, why would you have colors in binary format?
I don't know, I just know somone requested it!
I don't believe it's binary format, it's hexadecimal. ( Hex Colors: http://en.wikipedia.org/wiki/Hex_colors ) ( Binary *Code*: http://en.wikipedia.org/wiki/Binary_code )
Offline
I made them all, except the get costume from URL one!
You can use them but give credit!
Offline