News:

Simutrans Sites
Know our official sites. Find tools and resources for Simutrans.

help with scenario scripting?

Started by Tjoeker, June 03, 2016, 09:41:00 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Tjoeker

Good Morning (or evening or whatever),

I decided that i want to write some scenarios for Simutrans, but I can't seem to get a simple script working.
I don't know how to write c++ or squirrel. I do know how java works, so I think I can learn from reading the script a lot...
I've already read the scripts from the scenarios who came with the game, the swiss_mountains scenario was/is very interesting with it's terrain rules.
And I've gotten a scenario to work, but without any script in the .nut file.

Also I've read through this entire site, very interesting! But I can't get these to work in my script...

so here are the two things I want to achieve in my first script:

-every new month the government player gets an amount of cash: (something like) 0.001 times the amount of citizens in the world.

I assume the script would look like this?:
Quote from: script
int inhabitants = world::get_citizens([0])
int Tax = inhabitants*0.001

if new month starts function {
void player_1::book_cash ( integer Tax )    
but then again, this looks awfully wrong...  :D
*for the purple color: I do not know at all how to code this in simutrans


-a set timeline wich spawns new factories on specified coordinates. (can you set the name of the factory as well?)
This is an advanced one, but I think it's very interesting as I want to create an big timeline spawning factories, tourist attractions, remove border control (as the EU kicks in) ...

I hope somebody can help me out  :)
Thanks in advance.

Tjoeker


Tjoeker

very interesting!
however, this scenario doesn't include extra income for the government or a timeline :)

about the timeline:
Dwachs said (in the growth scenario topic) scripts can't build anything yet (2014). Is this possible by now?

about the tax income:
I can't get my script to work

function new_month()
{
void player_1::book_cash ( integer world::get_citizens([0])*0.001 ) ;
}

I get an error stating that I need an end statement between the "e" and "r" in player, wich makes no sense.  :D
any suggestions?

Combuijs

I don't know squirrel, but common sense would suggest you should leave out "void" and "integer" as you are calling a function, not declaring one.
Bob Marley: No woman, no cry

Programmer: No user, no bugs



Dwachs

Quote from: Tjoeker on June 04, 2016, 08:16:38 AM
Dwachs said (in the growth scenario topic) scripts can't build anything yet (2014). Is this possible by now?
Still not. I might try to throw in something if I find enough time.

Your piece of code should  be

player_x(1).book_cash ( world.get_citizens([0])*0.001 )

Parsley, sage, rosemary, and maggikraut.

Tjoeker

#5
ah, thank you!
the squirrel-api site used '::' instead of '.', hence I used these. :)
same goes for the "void" and "integer".

and for the build-script: no need to hurry, I'm still drawing the basics for my heightmap, then I have to start finetuning it and create a decent .sve...
In the meantime I'm still learning the Squirrel language.. :)


edit:hmm, tried the script, but it gives me this error: (see attached file)
edit: never mind, I solved it by creating a parameter with the formule outside the function and calling the parameter in the function.
edit: is it possible to book this amount of cash to the income in the finance window?

Combuijs

Quote from: Dwachs on June 04, 2016, 12:38:42 PM
Still not. I might try to throw in something if I find enough time.

Don't want to pressure you in anything, but I would love to have the possibility to create a new land attraction / factory chain / city on a random valid place. I see I already have the possibility to grow a city.
Bob Marley: No woman, no cry

Programmer: No user, no bugs



prissi

I am not sure, but if squirrel has a function to call a generic simutrans function, that can be achieved easily. If not already existing, such a low level API might be useful.

I mean something like simple_tool( coordinates, player, paramter_string ) just like simutrans does internally on those occassions anyway.

isidoro

Quote from: Yona-TYT on June 03, 2016, 09:40:42 PM
In this scenario the public service is mainly used. ;)
--> http://forum.simutrans.com/index.php?topic=13059.0


Unfortunately, the scenario isn't finished.  I was unable to fulfill my goals with the possibilities of scripting and my knowledge at that time...