Script: 8000 population....

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
Chuzehhh
Engineer
Engineer
Posts: 6
Joined: 12 Mar 2014 00:13

Script: 8000 population....

Post by Chuzehhh »

Hello everyone, i tried to make an script what have a objective for each company, reach 8000 pop, but i don't know any way to do that.
Someone can help me?
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Script: 8000 population....

Post by Zuu »

It is better if you ask specific questions about what parts you got stuck at.

Have you read the wiki articles about game scripts and also those for AIs? I also recommend reading source code of existing scripts if you have not done so yet.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Chuzehhh
Engineer
Engineer
Posts: 6
Joined: 12 Mar 2014 00:13

Re: Script: 8000 population....

Post by Chuzehhh »

So, i read all the topics of scripts, but i have no idea of how i can write an script.... My idea is, a company what reachs 8000 population win the game... And the game starts again...
R2dical
Traffic Manager
Traffic Manager
Posts: 163
Joined: 18 Mar 2013 22:22

Re: Script: 8000 population....

Post by R2dical »

Chuzehhh wrote:So, i read all the topics of scripts, but i have no idea of how i can write an script...
Writing a script is not cognitively simple, as you are actually doing "programming" and as such will need to understand at least the basics of what that means to start. Either check out some online tutorials (C++ = a comprehensive start), buy or download some free ebooks (C++, Java, Python even are good languages to learn basics from), or there is a link to a Squirrel tutorial for another game (GTA IV: MP, IIRC) in one of these threads, but can't seem to find it :(

Once done, check out the squirrel docs, wiki and API for details regarding OpenTTD and Squirrel.

If you have no experience with programming (or even modding) and think this will be easy, or expect that someone else will code the whole thing for you, maybe time to reconsider these assumptions...just friendly advice.

Note, AFAIK you can't actually "end the game" with GS, just display a message and/or update goals to reflect that this is what the GS decides.
Chuzehhh
Engineer
Engineer
Posts: 6
Joined: 12 Mar 2014 00:13

Re: Script: 8000 population....

Post by Chuzehhh »

Hey man, wait.. I'm a programmer but i program in C#, i don't any idea of how i can write an script of OpenTTD... Because i don't know the language what is used... You don't understand me... ;) I accept help of links in other sites, of how i can write a script. I edited the CityDomination script and got some success, but i want to write an script, mine script, because of this i make this topic..
R2dical
Traffic Manager
Traffic Manager
Posts: 163
Joined: 18 Mar 2013 22:22

Re: Script: 8000 population....

Post by R2dical »

Oh ok, well then you should be more than fine with squirrel syntax, only really big differences are dynamic typing, AI/GS Lists (objects) and privacy to some extent. The Squirrel docs are quite vague sometimes and formal definitions are not really useful IMO but if you are a programmer then they should be sufficient. The wiki (AI version, applies mostly to GS too), API and squirrel docs should be all you need.

So then what do you actually need help with? Be specific else it is difficult to provide assistance.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Script: 8000 population....

Post by Zuu »

A good start when you start to code from scratch is to not actually start from scratch but use the Minimal GS as boilerplate. It is found in a sticky thread of this forum. Using that you get a functional GS that can run. Then follow the instructions on what to change in info.nut and code your logic in main.nut.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Chuzehhh
Engineer
Engineer
Posts: 6
Joined: 12 Mar 2014 00:13

Re: Script: 8000 population....

Post by Chuzehhh »

Yeah i got the MinimalGS, but the events not work.. I try to copy the events of CityDomination, and not work... I want a goal, reach 8000 population.. just this.. i try to start from the beginning... but this not work too... :(

Code: Select all

Story.ShowMessage(company_id, GSText(GSText.STR_WELCOME, company_id));
I change the text on lang, but not work.. :/ i'm so sad about this.. i don't understand this language..
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Script: 8000 population....

Post by Zuu »

In general, it will be good if you are more explicit in what you did and how the outcome differ from the expected results. For example you say that you failed to merge code from CityDominator with Minimal GS. This is ok, but you can't get any real help by just giving this information. After merging the code, you got some final source code that you can upload here for example. If you got a fatal error, there will show an error in OpenTTD. Try to interpret this error and if you fail to fix it, you can then ask for help. But just saying "this doesn't work" will not give you any solution on how to proceed.

Chuzehhh wrote:Code:
Story.ShowMessage(company_id, GSText(GSText.STR_WELCOME, company_id));


I change the text on lang, but not work.. :/ i'm so sad about this.. i don't understand this language..
Make sure that lang/english.txt will remain in UTF-8 after you have changed this file.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4765
Joined: 09 Sep 2007 05:03
Location: home

Re: Script: 8000 population....

Post by Alberth »

If you don't understand what you are doing, your program is too big/complex. You should make it smaller/easier, until you understand it, then add stuff again, after understanding what you add, each step.

I'd also recommend to read the Squirrel manual http://squirrel-lang.org/doc/squirrel2.html entirely to get an idea of the language.
Start with a very simple script, for example, one that prints "I am alive" to the debug output every month, or so.
(Or a news message, or whatever way to show it's running.)

If you get stuck, try to be precises as possible in what you need help with. Show us what you tried (by publishing the source), what you expected, what happened exactly (did you get errors? what errors?), and how is what happened a problem?
Basically, try to provide all information such that we can try it on our own, and check that we get exactly the same answer as you.
(We may not actually do it, but that's a good aim at the level of detail to provide.)

The more precise you are, the more precise we can answer. Consider what kind of help could you provide for "my addition doesn't work" and for "10+4 gives the answer 0xE, why?". Hopefully you agree that the latter can give much better help information.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 13 guests