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

#1 2012-03-08 04:20:54

jurk
Scratcher
Registered: 2010-05-06
Posts: 100+

help with squeak!

we need help converting strings to instance variables


http://dl.dropbox.com/u/54228408/cool.png

Offline

 

#2 2012-03-08 04:59:14

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: help with squeak!

| t1 |
t1 _ 'a string'

I think...

EDIT: Whoops! Instance, not temporary. Sorry!  tongue

Last edited by Hardmath123 (2012-03-08 04:59:52)


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#3 2012-03-08 07:47:12

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

Re: help with squeak!

If you've declared the instance variable, you can just assign to it. You don't need to "convert" because Smalltalk is dynamically typed. e.g.:

"all fine on the same instance variable"
foo := 3.
foo := OrderedCollection new.
foo := 'Hello!'.

I wouldn't recommend doing this too often, though, because it can make your code confusing if an instance variable means two different things in two scenarios.


nXIII

Offline

 

#4 2012-03-09 03:19:24

jurk
Scratcher
Registered: 2010-05-06
Posts: 100+

Re: help with squeak!

no nXIII the other way like from a string to an instance variable  tongue
and not from a instance variable to a string  big_smile

Last edited by jurk (2012-03-09 03:19:47)


http://dl.dropbox.com/u/54228408/cool.png

Offline

 

#5 2012-03-09 07:45:48

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

Re: help with squeak!

jurk wrote:

no nXIII the other way like from a string to an instance variable  tongue
and not from a instance variable to a string  big_smile

You can't convert a string to an instance variable, unless you mean adding an instance variable dynamically, which you shouldn't do anyway (just use a Dictionary). You can assign to an instance variable, which is what I just showed you. You can't assign to a string.

Last edited by nXIII (2012-03-09 07:46:09)


nXIII

Offline

 

#6 2012-03-09 08:24:09

Pecola1
Scratcher
Registered: 2010-09-06
Posts: 1000+

Re: help with squeak!

Not sure why we are using the word 'convert' isn't it just changing its output?

Code:

blockbin _ hello world.

Or is it making a new instance variable named with the string...


If you are reading this, please read to the end, because if you don't you won't know what's at the end. Don't just skip to the end though otherwise you won't be able to read the middle, which is most important. Now you must be wondering why you just read all that, the reason is you may have not noticed something, read it again and see if you notice it this time  smile

Offline

 

#7 2012-03-10 11:40:00

jurk
Scratcher
Registered: 2010-05-06
Posts: 100+

Re: help with squeak!

sorry pecol1 that is not what i want  sad


http://dl.dropbox.com/u/54228408/cool.png

Offline

 

#8 2012-03-10 12:24:10

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

Re: help with squeak!

jurk wrote:

sorry pecol1 that is not what i want  sad

It would porbably help if you explained what you are trying to do.


nXIII

Offline

 

#9 2012-03-10 22:35:26

jurk
Scratcher
Registered: 2010-05-06
Posts: 100+

Re: help with squeak!

ok


http://dl.dropbox.com/u/54228408/cool.png

Offline

 

Board footer