Author Topic: Making a Scenario in Experimental  (Read 3088 times)

0 Members and 1 Guest are viewing this topic.

Offline zook2

Making a Scenario in Experimental
« on: November 25, 2014, 11:58:33 PM »
I've just begun to look into scenario-building (in Experimental, which may or may not support the entire scripting API - nobody knows for sure). I have some experience in programming (object-oriented PHP mostly), but it's been a while since I wrote a line of code. Thanks to Dwachs et al., there are now fantastic possibilities with scripting, but the documentation is a bit rudimentary. So I have a lot of beginner's questions and I'd be glad for some help.

1) Is there a way to print output to the "Scenario Debug" tab? Or the "scenario_msg" tab in the message center? I can catch the output in script.log, but an ingame message would be more comfortable.

2) When is "is_scenario_completed" called? Is it checked regularly or do I have to call it?

3) function new_month () doesn't seem to get called, at least not in fast-forward game mode (the double arrow icon).

4) Despite having
settings.set_industry_increase_every(0)
in function start(), the game built a new power plant at the beginning of a new month.

Offline ny911

Re: Making a Scenario in Experimental
« Reply #1 on: November 26, 2014, 12:16:04 AM »
sorry, I did post the answer at:
http://forum.simutrans.com/index.php?topic=14140.msg139947#msg139947

edit:
Quote
(in Experimental, which may or may not support the entire scripting API - nobody knows for sure)
As I know, all scripting API are supported in Experimental. This doesn't mean it will work or make any sense with the additional Experimental code in all cases.
« Last Edit: November 26, 2014, 12:26:12 AM by ny911 »

Offline zook2

Re: Making a Scenario in Experimental
« Reply #2 on: November 27, 2014, 12:41:26 AM »
My code-fu is rusty beyond belief. It took me ages to figure out some basic syntax. Anyway, when iterating through get_time like this:

t = world.get_time()
foreach (key,value in t) {
   print (key + value)
}

I get

Script: Print:   year1900
Script: Print:   month0

which is fine, but there is no mention of ticks.
http://dwachs.github.io/simutrans-sqapi-doc/classtime__ticks__x.html

Is that an Experimental quirk?

Offline zook2

Re: Making a Scenario in Experimental
« Reply #3 on: November 27, 2014, 01:31:30 AM »
I want to pay the player a certain amount of rubles (not game credits) when he transports coal. Is there a way to fire an event or somefink when a convoy reaches a stop and unloads cargo?

Offline ny911

Re: Making a Scenario in Experimental
« Reply #4 on: November 27, 2014, 10:40:00 AM »
Quote
t = world.get_time()
this is the world class not the class time_ticks

Quote
I want to pay the player a certain amount of rubles (not game credits) when he transports coal. Is there a way to fire an event or somefink when a convoy reaches a stop and unloads cargo?
Well, it might be better(and less work) to check the factory production. Save the value of get_delivered in a self owned array to calculate the difference and use this as the amount as the coal cargo.

http://dwachs.github.io/simutrans-sqapi-doc/classfactory__production__x.html

Offline zook2

Re: Making a Scenario in Experimental
« Reply #5 on: November 27, 2014, 09:34:26 PM »
I thought that the line in the API documentation
static time_ticks_x world::get_time    (       )    [static]
would return an object of the type "time_ticks_x", which has the public members month, year and ticks. But it returns only month and year. Also

a = time_x
a = time_ticks_x

results in an error.

Next, how do I realize a function that regularly checks anything when

function new_month (){
   coal_transported = factory_x( steel_mill.x, steel_mill.y ).input.Kohle
   print (coal_transported)
}
never gets called?

Offline ny911

Re: Making a Scenario in Experimental
« Reply #6 on: November 27, 2014, 09:51:07 PM »
sorry for confusion, e.g.

Code: [Select]
local now=world.get_time()   
local fractionOfMonth=1.0-(now.next_month_ticks.tofloat()-now.ticks)/now.ticks_per_month
(take a look into source of scenario "growth (by isidoro)", file scenario_class.nut line 200)

Quote
never gets called?
It's called automatically in simutrans, or do you mean it doesn't work in experimental

Code: [Select]
   print (coal_transported)I don't no this function "print" the only way to get a shown result at this function  is:
gui.add_message( "Hello World" )

Offline zook2

Re: Making a Scenario in Experimental
« Reply #7 on: November 28, 2014, 04:13:19 AM »
(take a look into source of scenario "growth (by isidoro)", file scenario_class.nut line 200)
Thanks, I'll have a look.

Quote
It's called automatically in simutrans, or do you mean it doesn't work in experimental
No, apparently it doesn't.

Quote
I don't no this function "print"
You can direct standard output to script.log.

Offline ny911

Re: Making a Scenario in Experimental
« Reply #8 on: November 28, 2014, 11:42:40 AM »
Thanks, so I now know a second way with "print"

I did make a small test with "function new_month() " and it doesn't work correct (better it don't work) in experimental.
tested with 112.3 Ex 11.31

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4251
  • Total likes: 177
  • Helpful: 149
  • Languages: EN, DE, AT
Re: Making a Scenario in Experimental
« Reply #9 on: November 29, 2014, 03:36:29 PM »
which is fine, but there is no mention of ticks.
http://dwachs.github.io/simutrans-sqapi-doc/classtime__ticks__x.html

Is that an Experimental quirk?
Maybe you are using a version of experimental that has not merged in this change of the api?
Parsley, sage, rosemary, and maggikraut.

Offline zook2

Re: Making a Scenario in Experimental
« Reply #10 on: November 29, 2014, 04:47:42 PM »
I've posted a bug report in Experimental
http://forum.simutrans.com/index.php?topic=14157.0
Perhaps you can point out there which API version would have to be merged?