For the tutorial I would like to be able to create a text that says "next step", and when pressed it executes a certain function, in this case proceed to the next step of the tutorial.
Something similar to the hyperlink tag.
That would be an escape route in case the tutorial is locked in any chapter / step. 8)
This can be one of those functions that return quickly. 8)
This is in r8242. Usage:
<a href="script:bla(19)">HERE</a>
If the string should not contain >,',". Please report any crashes, which might happen with ill-formed strings.
Many thanks, I will be very happy using this. ;D
I do not know how to make it work.
This was my best attempt: text.sc = "<a href=script:"+this.next_step()+">HERE[/url]"
What does ``this.next_step()'' return? What is the content of text.sc after this assign statement?
Edit: The argument of href must be enclosed in quotes like
<a href='script:bla(99)'>blub</a>
Quote from: Dwachs on May 27, 2017, 03:30:37 PM
What does ``this.next_step()'' return? What is the content of text.sc after this assign statement?
It's just crazy of me. :P
Quote from: Dwachs on May 27, 2017, 03:30:37 PM
Edit: The argument of href must be enclosed in quotes like
<a href='script:bla(99)'>blub</a>
Why is a value sent to the "bla ()" function? Works without needing that number. ???
One small detail, the function does not show a popup window when a value other than null is returned.
Quote from: Yona-TYT on May 27, 2017, 10:21:26 PM
Why is a value sent to the "bla ()" function? Works without needing that number. ???
This was just to demonstrate that you can pass arguments to the function ;)
Quote
One small detail, the function does not show a popup window when a value other than null is returned.
The return value is not processed. There will be a popup only if some error occured when compiling the code after 'script:'
There are some moments when you can not skip step / chapter (scenario can be damaged), it would be nice to be able to show some message on the return.Otherwise, players will click repeatedly without knowing why nothing happens. ;)
Can't the function being called check what value will be returned and show a message if it notices it's an error?
Quote from: An_dz on May 29, 2017, 08:56:23 PM
Can't the function being called check what value will be returned and show a message if it notices it's an error?
Similar to the return of "is_convoy_allowed" to name an example. ;)
By the way I'm very happy with "is_convoy_allowed". ;D
If the click would trigger an error, why put the scripted link in the text?
Quote from: Dwachs on May 30, 2017, 06:08:27 AM
If the click would trigger an error, why put the scripted link in the text?
I do not mean an error as such, I mean the return value when this is different than null.
Example:
function script_text()
{
if (!correct_cov)
return translate("You can not advance of step at this time.")
else
return null
}
You can test script-text in the tutorial: http://files.simutrans.com/index.php/s/zuwwVADjzLYdki6 (http://files.simutrans.com/index.php/s/zuwwVADjzLYdki6) ;)
It seems a bit strange that this is the only function (immediate return) that does not show a popup. ???