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

#1 2010-12-15 16:52:08

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

smalltalk coder needed for a question!

I need to let a block set the variable t3 to several lines from a webpage.

One line works like this:

|t3 link|

t3_ self readLine: 5 FromUrl: link

but I am using it to read a file where more than one line of the file needs to be set to t3 so that the smalltalk code sets t3 to:

lines 5 to (number of lines in file at URL, link) of link

Any ideas?


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

Offline

 

#2 2010-12-15 16:53:22

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

Re: smalltalk coder needed for a question!

Do you want line breaks, or a long string?


You can now reach me on Twitter @johnnydean1_

Offline

 

#3 2010-12-15 17:00:01

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

Re: smalltalk coder needed for a question!

it's reading block code stored online, I don't think that block code NEEDS line breaks, so I think one line will do.


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

Offline

 

#4 2010-12-15 17:12:48

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

Re: smalltalk coder needed for a question!

I can do it tommrow, not now sorry.


You can now reach me on Twitter @johnnydean1_

Offline

 

#5 2010-12-15 17:15:46

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: smalltalk coder needed for a question!

sparks wrote:

I need to let a block set the variable t3 to several lines from a webpage.

One line works like this:

|t3 link|

t3_ self readLine: 5 FromUrl: link

but I am using it to read a file where more than one line of the file needs to be set to t3 so that the smalltalk code sets t3 to:

lines 5 to (number of lines in file at URL, link) of link

Any ideas?

|t3 t4 time totalTime link|
time = totalTime ifFalse:
[t3_ self readLine: 5 FromUrl: link.
t4_ t3 , t4.]
ifTrue:
[^ t4].


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#6 2010-12-15 17:28:45

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

Re: smalltalk coder needed for a question!

bbbeb wrote:

sparks wrote:

I need to let a block set the variable t3 to several lines from a webpage.

One line works like this:

|t3 link|

t3_ self readLine: 5 FromUrl: link

but I am using it to read a file where more than one line of the file needs to be set to t3 so that the smalltalk code sets t3 to:

lines 5 to (number of lines in file at URL, link) of link

Any ideas?

|t3 t4 time totalTime link|
time = totalTime ifFalse:
[t3_ self readLine: 5 FromUrl: link.
t4_ t3 , t4.]
ifTrue:
[^ t4].

How do I set t3 to that?


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

Offline

 

#7 2010-12-15 17:30:13

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

Re: smalltalk coder needed for a question!

sparks wrote:

bbbeb wrote:

sparks wrote:

I need to let a block set the variable t3 to several lines from a webpage.

One line works like this:

|t3 link|

t3_ self readLine: 5 FromUrl: link

but I am using it to read a file where more than one line of the file needs to be set to t3 so that the smalltalk code sets t3 to:

lines 5 to (number of lines in file at URL, link) of link

Any ideas?

|t3 t4 time totalTime link|
time = totalTime ifFalse:
[t3_ self readLine: 5 FromUrl: link.
t4_ t3 , t4.]
ifTrue:
[^ t4].

How do I set t3 to that?

|t3 t4 t5 time totalTime link|
t5_ ''.
time = totalTime ifFalse:
[t3_ self readLine: 5 FromUrl: link.
t4_ t3 , t4.]
ifTrue:
[t5_t4].

t3_ t5.


You can now reach me on Twitter @johnnydean1_

Offline

 

#8 2010-12-15 17:35:28

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

Re: smalltalk coder needed for a question!

isn't that reading line 5 over and over again?


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

Offline

 

#9 2010-12-15 17:36:59

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

Re: smalltalk coder needed for a question!

I dunno, wasn't my code XD


You can now reach me on Twitter @johnnydean1_

Offline

 

#10 2010-12-15 23:14:07

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: smalltalk coder needed for a question!

bbbeb wrote:

sparks wrote:

I need to let a block set the variable t3 to several lines from a webpage.

One line works like this:

|t3 link|

t3_ self readLine: 5 FromUrl: link

but I am using it to read a file where more than one line of the file needs to be set to t3 so that the smalltalk code sets t3 to:

lines 5 to (number of lines in file at URL, link) of link

Any ideas?

|t3 t4 time totalTime link lineNum|
time = totalTime ifFalse:
[t3_ self readLine: lineNum FromUrl: link.
t4_ t3 , t4.]
ifTrue:
[t3_ t4].
^ t3.

There. I fixed it. I was in a rush.

Last edited by bbbeb (2010-12-15 23:14:53)


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#11 2010-12-16 14:49:42

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

Re: smalltalk coder needed for a question!

Here's a quicky fixy  smile

Code:

| t3 link lns res curr |

t3 _ self readLine: 5 FromUrl: link.

lns _ t3 lines size.
res _ t3 lines at: 5.
curr _ 5.
lns - 5 timesRepeat:
[curr _ crr +1.
res _ '
' , t3 lines at: curr].

^ res

there's definitely a much easier way to do this, but i've been working too much with VB recently and forgot half of my Squeak  tongue

Offline

 

#12 2010-12-16 14:59:59

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

Re: smalltalk coder needed for a question!

Why is this block returning an error?

$String$ as one line

|t3 t4 time totalTime  lineNum|
totalTime_ t1 asString lines size.
time_ 1.
time = totalTime ifFalse:
[
lineNum_time.
t3_ t1 asString lines at: lineNum.
t4_ t4 , ' ', t3.
time_ time + 1.]
ifTrue:
[^t4.].

??

(bring a string of more than one line and puts all the strings on one line with a space seperating each former line.)

Last edited by sparks (2010-12-16 15:02:36)


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

Offline

 

#13 2010-12-16 15:13:21

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

Re: smalltalk coder needed for a question!

sparks wrote:

$String$ as one line

|t3 t4 time totalTime lineNum|
totalTime_ t1 lines size.
time_ 1.
time = totalTime
ifFalse:
[
lineNum_time.
t3_ t1 asString lines at: lineNum.
t4_ t4 , ' ', t3.
time_ time + 1.]
ifTrue:
[^t4.].


You can now reach me on Twitter @johnnydean1_

Offline

 

#14 2010-12-16 15:22:32

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

Re: smalltalk coder needed for a question!

dw, I edited your "compile $List$ with $String$ as breaker" and change it to "turn $String$ into one line with $String$ as breaker"!

Thanks!


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

Offline

 

#15 2010-12-16 16:07:29

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

Re: smalltalk coder needed for a question!

ok


You can now reach me on Twitter @johnnydean1_

Offline

 

Board footer