It's free to join Gamasutra!|Have a question? Want to know who runs this site? Here you go.|Targeting the game development market with your product or service? Get info on advertising here.||For altering your contact information or changing email subscription preferences.
Registered members can log in here.Back to the home page.

Search articles, jobs, buyers guide, and more.

By Wyeth Ridgway
Gamasutra
October 8, 1999

Letters to the Editor:
Write a letter
View all letters


Features

Contents

Introduction

MaxScript 101

Writing MaxScripts

Writing a File Exporter

Scripting a Game Editor

Writing a File Exporter in MaxScript

In order to better illustrate exactly how the development process works, I’ll describe the process of writing an fairly rudimentary script, and what problems arose. I chose to write a geometry exporter, because it forced me to learn how models were internally organized in Max.

When I began, I knew I wanted to export geometry to the Alias RTG (Real-Time Games) format. I have used this format for many years because of its simplicity. With the wide variety of example scripts to look at, I knew that I could probably find source code that illustrated the geometry traversal and access that I would require.

After poking around in the "scripts" directory, I found a file called MSXExport.ms which saves a scene (including geometry, cameras, and so on) as a script file. Running this script file rebuilds the entire scene inside Max, which was very close to what I wanted to do. The script opens and saves data to a file, traversing the internal data structures in Max to examine every object. However, the script saves to a file the sequence of commands issued in Max to create an object, not the polygonal data itself. I went through the help files to learn how to access the vertices, polygons, texture coordinates, and normals. I then modified the save code to output in the RTG file format, accessing these fields and writing the values. All that remained was some minor modifications to the GUI and the script was complete. It was very surprising just how easy it was.

I spent about ten hours writing and debugging my geometry export script. If I had to do it again, it would take about three hours, since I am now considerably more comfortable using the language. Familiarity with the help files was a big benefit when it came time to write my own scripts, but there were still some stumbling blocks. The most annoying problem involved file I/O: when there was an error executing the script, the file handle to the output file was left open. I tried typing a line into the Listener to close the files, but it said the variable was not defined. The only way to close the file so I could view the output was to close Max. I think there is probably a way to work around this, but I have not yet found it. The other problems I had were minor, and mainly stemmed from a lack of understanding of how to approach a problem. This can be greatly alleviated by scanning through the example scripts, which are generally very readable.


Scripting a Game Editor


join | contact us | advertise | write | my profile
news | features | companies | jobs | resumes | education | product guide | projects | store



Copyright © 2003 CMP Media LLC

privacy policy
| terms of service