Page 1 of 1
Script: 8000 population....
Posted: 12 Mar 2014 00:19
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?
Re: Script: 8000 population....
Posted: 12 Mar 2014 18:09
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.
Re: Script: 8000 population....
Posted: 14 Mar 2014 15:59
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...
Re: Script: 8000 population....
Posted: 14 Mar 2014 22:16
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.
Re: Script: 8000 population....
Posted: 14 Mar 2014 22:27
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..
Re: Script: 8000 population....
Posted: 14 Mar 2014 22:46
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.
Re: Script: 8000 population....
Posted: 15 Mar 2014 09:03
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.
Re: Script: 8000 population....
Posted: 15 Mar 2014 13:03
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..
Re: Script: 8000 population....
Posted: 16 Mar 2014 15:59
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.
Re: Script: 8000 population....
Posted: 16 Mar 2014 17:24
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.