J6/Project Manager/Life

From J Wiki
Jump to navigation Jump to search

A project to build a Game of Life application is in distribution directory system\examples\life. The application is essentially the same as the demo in Studio|Demos|life.

To experiment with this project, first copy it to your own Projects folder. Do the following:

1. Ensure that a folder named Projects is defined, so that the following should expand ~Projects into the correct full directory name (if necessary, set up Projects in Edit|Configure|Folders). For example:

   jpath '~Projects\life'
c:\j6\user\projects\life

2. Copy the directory system\examples\life to your Projects folder.

3. In the new directory, rename file lifeijp.txt to life.ijp.

To test this, load J, and enter:

   load 'dir'
   dir jpath '~Projects\life'
build.ijs          1179 25-Jul-05 08:52:54
data.ijs           8486 25-Jul-05 08:52:54
file.ijs           1235 25-Jul-05 08:52:54
...

Now load the Project Manager, and you should be able to browse to the Life project.

Experiments

1. Click the Test button to run the application.

2. Open the test.ijs script in the Project tab and note the steps taken:

  • build the life script
  • load the life script
  • load a test file (here, test0.ijs)

The actual test is set up in the test0.ijs script. It is useful to put the test in another script, so that several such test scripts can be set up. To run any script, change test.ijs to load that script.

3. Open the test0.ijs script from the Other tab. This runs life with specific set up values.

Try changing one of these values, as below, then click the Test button again:

CELLCOLOR__a=: 255 0 0

4. Now switch to the Source tab and open script init. Try changing a value, for example as below, then click the Test button again. Note that the life script has been rebuilt with the new value:

SCALE=: 3

5. The script can be run from the J session. Try:

   load '~Projects\life\life.ijs'
   runlife''

6. In the Project tab, view the target script. Note that it starts by loading script gl2.ijs, which is the 2D graphics api.

7. To build a script that includes all required files, and can be run by itself, do the following:

Open menu Project|Build Options, then:

  • Select "Project Libraries | Include". This includes the gl2.ijs script in the target script.
  • Select "Standard Libraries | Include". This includes the standard libraries in the target script.
  • In "Append to file", enter the following to start the application after it has loaded:
   runlife ''

Click Build Now, then close the dialog. View the target script, and note that the library scripts are now included.

In the J session, ensure that the application works correctly by entering:

   load '~Projects\life\life.ijs'

Now close J, and create a shortcut that starts J, with the command line (use the correct directory names):

c:\j6\j.exe c:\j6\user\projects\life\life.ijs
 This should work, otherwise errors will be reported in the J session. Once it is working properly, add -jprofile to the command line so that the normal J session does not appear:
c:\j6\j.exe -jprofile c:\j6\user\projects\life\life.ijs

Comments

1. The project is split over several source files. Typically these will include:

  • an initialization script
  • a utilities script
  • one or more scripts with the application logic
  • one or more scripts, each with a form definition
  • a run script, with verbs to run the application

2. Larger applications may be spread over several project files.

3. The project loads into its own locale: plife. This ensures that names used in the project do not conflict with other names in the system.

4. The project locale is set in the Project|Build Options dialog. Any name can be used, though it is typical to use the following prefixes:

p private or personal
c class
i interface
j a J system class

Note that the system demo uses locale: jlife.