Is there a way to combine two GameScripts?

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
Lechuza
Engineer
Engineer
Posts: 16
Joined: 30 Oct 2014 01:33

Is there a way to combine two GameScripts?

Post 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! :)
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: Is there a way to combine two GameScripts?

Post 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).
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Is there a way to combine two GameScripts?

Post 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.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
madprof
Engineer
Engineer
Posts: 13
Joined: 02 Jan 2016 22:00

Re: Is there a way to combine two GameScripts?

Post 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? :?
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Is there a way to combine two GameScripts?

Post 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.
Being a retired OpenTTD developer does not mean I know what I am doing.
madprof
Engineer
Engineer
Posts: 13
Joined: 02 Jan 2016 22:00

Re: Is there a way to combine two GameScripts?

Post 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 :/
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Is there a way to combine two GameScripts?

Post 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 :)
Being a retired OpenTTD developer does not mean I know what I am doing.
madprof
Engineer
Engineer
Posts: 13
Joined: 02 Jan 2016 22:00

Re: Is there a way to combine two GameScripts?

Post by madprof »

Many thanks Alberth, I'll assign one personality to the conceptual side :))
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 7 guests