Discuss Scratch

EMPedemonte20
Scratcher
100+ posts

^ self t1 ???

Hi, I am wondering if anyone knows how to call a method in squeak from a variable. for example:
[b]Do: t1 and restart[/b]
self t1; restart
I want to call the method that is t1, but I can't get it to use a method called by a variable.
Any help appreciated

There are 10 types of people in this world. People who know binary code, and people who don't.
My mod, NoMod!!!
davidkt
Scratcher
1000+ posts

^ self t1 ???

Is there an eval command in Squeak?
Then you could do:
eval('self' + t1 + ';restart')
That may not be Squeak's exact syntax, but Squeaks exact syntax is confusing and ugly, so…

Edit: It's syntax-highlighted! That means there is an eval command in Squeak! There's your code, just add the correct syntax.

Last edited by davidkt (July 2, 2014 21:21:07)


Remember when I looked like this? I still do.


Float, my Scratch 2.0 mod | My (somewhat under-construction) blog
nXIII
Scratcher
1000+ posts

^ self t1 ???

If you describe what you're trying to do, there's most likely a better way to do it than this.

However, this will work:
performAndRestart: message
    self perform: message asSymbol; restart

Also, please use real variable/parameter names. Just because Squeak's compiler ignores them doesn't mean you have to. If it refuses to save them, you need to add a .changes file.

nXIII · GitHub

Powered by DjangoBB