Page 1 of 1

ExternalLuxMapGenerator (beta)

Posted: Mon Jun 07, 2004 7:12 pm
by dustin
I have put together a package to create a LuxMapGenerator plug-in using an external script (like a perl script).

Download it <a href="/download/ExternalMapGeneratorSDK.zip">here</a>. The readme.txt file has the instructions.

The currently released version of Lux does not support LuxMapGenerator plug-ins. So you must download a beta version of Lux which does <a href="/download/Lux_mac_beta.zip">here</a>. This beta is macintosh only.

Posted: Tue Jun 08, 2004 4:52 am
by rip
Thanks Dustin. I've downloaded the packet and will have a crack at it over lunch.

rip

Posted: Tue Jun 08, 2004 6:15 pm
by rip
Hi Dustin,

Could you overload getChoices with

public String[] getChoices( MapLoader loader )
{
}

This would allow me to call my script from getChoices, to have it return a dynamic list of supported sizes. So if I want to change what is supported, I only need do so in the script itself. At the moment, I'm doing this (below) to test it, but you can see why it is bad-bad-bad. :)

Also, aside, how do you declare a new String with an unknown number of slots? At the moment, I _know_ there are four sizes available, so I set it to four. If I add one in the script, I get an index out-of-range error (and quite rightly), and if I only return 3, I end up adding a blank line to the world size list-box in Lux. If you don't want to be my java tutor on this, no worries, I've got a couple of people I can ask the next time I see them :)

Thanks!

rip

public String[] getChoices()
{
System.out.println("MabilGen: getChoices() called...");
String[] choices = new String[4];
String[] command =
{
"/Users/rip/Library/Application Support/Lux/MapGenerators/" + scriptName,
"choices"
};

try
{
Process pr = Runtime.getRuntime().exec( command );
BufferedReader in =
new BufferedReader(new InputStreamReader(pr.getInputStream()));
String result;
int i = 0;
while ( ( result = in.readLine()) != null )
{
if( result != "")
{
choices = new String ( result );
System.out.println("MabilGen: Choice "+choices+" added to list.");
i++;
}
...

Posted: Tue Jun 08, 2004 6:50 pm
by dustin
> Could you overload getChoices with ...

I can make MapLoader's getMapGeneratorPath() function static, which will mean you won't need a MapLoader reference to call the function. I should have done this in the first place.

> how do you declare a new String [array] with an unknown number of slots?

You can't do it using an array (anything with a [] is an array). You can do it using a Vector of String's instead. Vector is like an array but it can grow and shrink. Here's the code:

Code: Select all

Vector choicesVector = new Vector();

... do some stuff. Next line should be inside the loop ...

choicesVector.add( result );

... do more stuff. An array must be returned, so right at the end we copy the Vector into a String array ...

String[] choices = new String[choicesVector.size()];
choicesVector.copyInto( choices );
return choices;
Perhaps it would be easier to have the choices() function return a Vector instead of a String array. I'm pretty sure I left a 'import java.util.*;' line at the top of the file, this is required to use the Vector class.

FYI: In java 'functions' are often called 'methods', so I might use that term sometimes.

Posted: Wed Jun 09, 2004 4:54 am
by rip
Hi Dustin,

Ok, I've rewritten it with the Vector type and that's working.

I've still got a question about the seed, and what it represents. Is it simply a way to reduce the chance of overwriting existing luxb files, or 'given a seed, return an absolutely identical map (AIM)' regardless of the OS/Machine/Version in use.

At the moment I'm just using the seed to seed the srand function, so on my machine, if you give a seed 1234 today, you get the same map if you seed 1234 tomorrow. Unfortunately this doesn't hold up once you move outside my iBook, as the random number systems on different hw does not return the same arbitrary series of pseudo-random numbers.

If I need to return an AIM, I know how I would do it, but I need to know if I need to implement that stuff (it would, however, essentially reduce the 'randomness' of the map generator)

rip

Posted: Wed Jun 09, 2004 11:51 am
by dustin
The seed is just meant to seed your random number generator. My testing with the java random number generator shows that the same seed will produce the same sequence even on different machines (OSX G5 and Windows 98 intel give the same results). I think that the perl random generator might do the same. I just did a little test that shows that the perl sequence is the same on my G5 and on a linux box.

So anyway, the conclusion is just use the seed in srand() and don't worry about it.