News:

Use the "Forum Search"
It may help you to find anything in the forum ;).

Making a Scenario in Experimental

Started by zook2, November 25, 2014, 11:58:33 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

zook2

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.

ny911

#1
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.

zook2

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?

zook2

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?

ny911

Quotet = world.get_time()
this is the world class not the class time_ticks

QuoteI 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

zook2

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?

ny911

sorry for confusion, e.g.

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)

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

   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" )

zook2

Quote from: ny911 on November 27, 2014, 09:51:07 PM
(take a look into source of scenario "growth (by isidoro)", file scenario_class.nut line 200)
Thanks, I'll have a look.

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

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

ny911

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

Dwachs

Quote from: zook2 on November 27, 2014, 12:41:26 AM
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.

zook2

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?