Page 1 of 1

Is there a way to combine two GameScripts?

Posted: 04 Nov 2014 18:35
by Lechuza
I believe we cannot use more than one gamescript, so is there a way to combine two gamescripts?

I would like to use the Balance City Growth and the Industry Constructor gamescripts. I tried opening their source code and combining both of them into one, then I used 7Zip to compress it into tar and I put it in the same folder where the other two where. The problem is the game is not seeing it for some reason. Obviously I did something wrong but I am not sure as to what it could have been.

Any help is appreciated! :)

Re: Is there a way to combine two GameScripts?

Posted: 04 Nov 2014 19:00
by krinn
Nope, you can only run 1 instance of a gamescript.
So even if you combine two into one package, they have their instance, and it will remain 2 instances.
I'm unsure how openttd try to handle that, loading the first only, throwing message away or replacing the first with the second, anyway, i think openttd match package name with directory structure name (abc.tgz content is hold into an abc.version directory)

You can combine their source code into one package, and even share that with others if the license allow that (generally they are gplv2 so it's something allow). But it will use its own (one) instance (named as you wish).

Re: Is there a way to combine two GameScripts?

Posted: 04 Nov 2014 21:47
by Zuu
It is possible to create a pack of many GSes just like there are patch packs. But just as with patch packs, this needs work from someone to integrate them with each other and make sure there any logical conflicts between them get resolved and not just something that compiles.

For example there should only be one info.nut and one main.nut with only one ::Start() method that get called by OpenTTD when the GS starts.

As long as the two GSes don't have global scope name conflicts, replace API methods with their own variants or similar, it is mostly that you need rename the GS main.nut files to some other name, change them so that their main loop is not looping but a function you can call from your new main.nut and the combined main loop. Similar things need to be done for the Save/Load methods.


For someone who has written a GS this is something not too hard. But if you have never written a GS or an AI, I would recommend start doing that before trying to combine two. You will then learn how a proper GS is made, learn the Squirrel programming language etc. which is good to know in order to make a GS pack.

Re: Is there a way to combine two GameScripts?

Posted: 04 Jan 2016 11:40
by madprof
For combining perhaps there should be a change in thinking about scripts and perhaps writing them more like libraries? Or providing library ports of those scripts? :?

Re: Is there a way to combine two GameScripts?

Posted: 04 Jan 2016 15:33
by Alberth
madprof wrote:For combining perhaps there should be a change in thinking about scripts and perhaps writing them more like libraries? Or providing library ports of those scripts? :?
I am not sure it makes a lot of sense. A GS is like a captain at a ship. If you have more captains, you'll get clashes between them, as they all believe they are boss of everything.

If you want to combine arbitrary GSes, that is the first conceptual problem you have to solve.

Re: Is there a way to combine two GameScripts?

Posted: 04 Jan 2016 23:19
by madprof
You mean, like who is captain atm? I think I see a thought process starting ;)

I am just doing a random conceptual rambling thing since I only actually looked at my first nut file today

_____ edit ____
actually I think I was rephrasing what zuu was saying. I think I did choose the right display name :/

Re: Is there a way to combine two GameScripts?

Posted: 05 Jan 2016 07:22
by Alberth
Well, both the conceptual problem of multiple bosses over one world, and the practical problem of how to get stuff concretely running need to be addressed at some point. It's perfectly feasible to just start with the practical approach and see where you end, without much worrying about the conceptual problems.

Enjoy the journey into the game script world, professor :)

Re: Is there a way to combine two GameScripts?

Posted: 08 Jan 2016 02:28
by madprof
Many thanks Alberth, I'll assign one personality to the conceptual side :))