Wednesday 28 October 2015

How to get Smalltalk to start a specific app on startup

How do I get Squeak to start running my game app as soon as the image is opened?

* Open the World menu.
* Click on the "do..." item
* Choose "edit this list"
* Add a line saying:
 Smalltalk saveSession. MyGameMorph openInWorld.
[Note this _needs_ to be a single line, so it might be easier to have a
method on the class side of your game called "saveAndStartup" which
you'd enter here].
* Accept the changes
* Click on the entry on the "do" menu.

Now your game comes up nicely. The reason why I (at times ;-) prefer
that approach is that by simply saving the image _without_ using the
above menu entry you get it back to the state where your game is not
starting up.
-----------

It's easy-

First, add a #shutDown method on the class-side of your class.
and then execute "Smalltalk addToStartUpList: YourClass."

There's also a #addToShutDownList: if you need a method called when the
image is shutting down.  Just throw on a #shutDown method on the class
side.

Also of interest may be SystemDictionary>>#addToShutDownList:after:
and SystemDictionary>>#addToStartUpList:after: which do the same thing,
but allow you to have some order in which they occur.

------

A:</b> There are a few different ways to do this:
1. You may be able to just save your image in an interesting configuration, i.e. with your application open. Keep in mind that when the image starts, it starts <b>exactly</b> where it left off.
2. As a variation, you can save your image like this (do all this code together in one DoIt):
= Smalltalk snapshot: true andQuit: false.
= self inform: 'Hello, world.' "Replace this with your application-starting code"
3. You can use addToStartUpList: to register any object that understands startUp:; that object's startUp: method will be invoked every time the system starts. (Look in "snapshot and quit" under class SystemDictionary for details).
4. You can specify a script file when starting up Squeak, named on the command line. See *Writing scripts* for details.
5. . Open the *World menu*.
. Click on the "do..." item
. Choose "edit this list"
. Add a line saying:
Smalltalk saveSession. MyGameMorph openInWorld.
[Note this _needs_ to be a single line, so it might be easier to have a method on the class side of your game called "saveAndStartup" which you'd enter here].
. Accept the changes
. Click on the entry on the "do" menu.
Now your game comes up nicely. The reason why I (at times ;-) prefer that approach is that by simply saving the image _without_ using the above menu entry you get it back to the state where your game is not starting up.

No comments:

Post a Comment