Author Topic: help with scenario scripting?  (Read 2390 times)

0 Members and 1 Guest are viewing this topic.

Offline Tjoeker

help with scenario scripting?
« on: June 03, 2016, 09:41:00 AM »
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
« Last Edit: June 03, 2016, 02:09:01 PM by Tjoeker »

Offline Yona-TYT

Re: help with scenario scripting?
« Reply #1 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

Offline Tjoeker

Re: help with scenario scripting?
« Reply #2 on: June 04, 2016, 08:16:38 AM »
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

Code: [Select]
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?

Offline Combuijs

  • Web Team
  • Devotee
  • *
  • Posts: 1387
  • Total likes: 22
  • Helpful: 53
  • Maintainer of maps.simutrans.com
    • Combuijs
  • Languages: EN, NL
Re: help with scenario scripting?
« Reply #3 on: June 04, 2016, 09:09:05 AM »
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



Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4251
  • Total likes: 177
  • Helpful: 149
  • Languages: EN, DE, AT
Re: help with scenario scripting?
« Reply #4 on: June 04, 2016, 12:38:42 PM »
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
Code: [Select]
player_x(1).book_cash ( world.get_citizens([0])*0.001 )
Parsley, sage, rosemary, and maggikraut.

Offline Tjoeker

Re: help with scenario scripting?
« Reply #5 on: June 04, 2016, 01:42:13 PM »
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?
« Last Edit: June 04, 2016, 03:29:16 PM by Tjoeker »

Offline Combuijs

  • Web Team
  • Devotee
  • *
  • Posts: 1387
  • Total likes: 22
  • Helpful: 53
  • Maintainer of maps.simutrans.com
    • Combuijs
  • Languages: EN, NL
Re: help with scenario scripting?
« Reply #6 on: June 05, 2016, 01:25:20 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



Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 8823
  • Total likes: 323
  • Helpful: 229
  • Languages: De,EN,JP
Re: help with scenario scripting?
« Reply #7 on: June 05, 2016, 09:41:37 PM »
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.

Offline isidoro

Re: help with scenario scripting?
« Reply #8 on: June 06, 2016, 12:24:38 AM »
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...